Answers for "remove an element from array php based on value"

PHP
17

php delete element by value

$colors = array("blue","green","red");

//delete element in array by value "green"
if (($key = array_search("green", $colors)) !== false) {
    unset($colors[$key]);
}
Posted by: Guest on October-30-2019
0

php array remove value if exists

<?php
$myArray = array ('Alan', 'Peter', 'Linus', 'Larry');
$pos = array_search('Linus', $myArray);
echo 'Linus found at: '.$pos;
// Remove from array
unset($myArray[$pos]);
print_r($myArray);
?>
Posted by: Guest on April-07-2021

Code answers related to "remove an element from array php based on value"

Browse Popular Code Answers by Language