remove value in array php 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: php remove item array
$items = ['banana', 'apple'];
unset($items[0]);
var_dump($items);
Example 3: php array remove value if exists
<?php
$myArray = array ('Alan', 'Peter', 'Linus', 'Larry');
$pos = array_search('Linus', $myArray);
echo 'Linus found at: '.$pos;
unset($myArray[$pos]);
print_r($myArray);
?>
Example 4: php remove element from array by value
foreach($appsList as $key => $app) {
if($app["app_status"] !== "approved") {
unset($appsList[$key]);
}
}