Answers for "remove array element php by value"

PHP
17

php delete element by value

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

//delete element in array by value "green"
if (($key = array_search("green", $colors)) !== false) {
    unset($colors[$key]);
}
Posted by: Guest on October-30-2019
0

remove item in an array php

//NO KEY supplied
$message array("a", "b", "c", "d");
$del_val = "b";
if (($key = array_search($del_val, $messages)) !== false) {
    unset($messages[$key]);
}
Posted by: Guest on June-10-2021
0

how to delete item from array php

$array = [0 => "a", 1 => "b", 2 => "c"];
unset($array[1]);
Posted by: Guest on October-20-2020

Code answers related to "remove array element php by value"

Browse Popular Code Answers by Language