PHP Remove Element from Array by Value Example
I will explain step by step tutorial php remove element from array by value. i would like to share with you how to remove array element by value in php. you will learn php remove item from array by value. you will learn php remove item from array based on value. Here, Creating a basic example of php remove element from array with specific value.
Here, i will give you very simple example of how to remove item by value in php.
Example 1:
index.php
<?php
function remove_element($array, $value) {
if(($key = array_search($value,$array)) !== false) {
unset($array[$key]);
}
}
$myArray = ["Apple", "Banana", "Mango"];
remove_element($myArray, 'Banana');
print_r($myArray);
?>
Output:
Array
(
[0] => Apple
[1] => Mango
)
i hope it can help you...