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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Remove First Element from Array in PHP?
- How to Get First Element of Array in Javascript?
- How to Remove Specific Value from Array in JQuery?
- How to Remove Specific Element by Value from Array in PHP?
- How to Get Maximum Key Value of Array in PHP?
- How to Remove Empty Values from Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Remove Null Values from Array in PHP?
- How to Merge Two Array with Same Keys without Loop in PHP?