Answers for "php remove array 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

php remove specific element from array

if (($key = array_search('strawberry', $array)) !== false) {
    unset($array[$key]);
}
Posted by: Guest on July-08-2020
14

php delete element from array

//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
Posted by: Guest on August-06-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

remove array values php

array_splice(array, start, length, array)
Posted by: Guest on November-03-2020

Code answers related to "php remove array by value"

Browse Popular Code Answers by Language