array php remove values condition code example
Example 1: 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);
?>
Example 2: php conditionally remove element from array
foreach ($array as $key => $element) {
if ($element['age'] > 90) {
unset($array[$key]);
}
}