php remove key from array if exists code example
Example 1: php delete element by value
$colors = array("blue","green","red");
if (($key = array_search("green", $colors)) !== false) {
unset($colors[$key]);
}
Example 2: searching and removing element from an array php
<?php
$hackers = array ('Alan Kay', 'Peter Norvig', 'Linus Trovalds', 'Larry Page');
print_r($hackers);
$pos = array_search('Linus Trovalds', $hackers);
echo 'Linus Trovalds found at: ' . $pos;
unset($hackers[$pos]);
print_r($hackers);