php array key remove 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 unset array key
unset($dataArray['key']);
Example 3: php remove element from array
$arr = array('a' => 1, 'b' => 2, 'c' => 3);
unset($arr['b']);
$arr = array(1, 2, 3);
array_splice($arr, 1, 1);
Example 4: php array remove keys keep values
<?php
$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));
?>
Array
(
[0] => XL
[1] => gold
)
Example 5: php erase element from array
foreach ($items as $key =>$item){
if(condition){
unset($item[$key]);
}
}