Syk
0
Q:

php delete array item by value

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

//delete element in array by value "green"
if (($key = array_search("green", $colors)) !== false) {
    unset($colors[$key]);
}
9
//Delete array items with unset(no re-index) or array_splice(re-index)
$colors = array("red","blue","green");                             
unset($colors[1]);//remove second element, do not re-index array

$colors = array("red","blue","green");
array_splice($colors, 1, 1); //remove second element, re-index array
10
$array = [0 => "a", 1 => "b", 2 => "c"];
unset($array[1]);
0

New to Communities?

Join the community