Answers for "remove keys from array"

PHP
17

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]);
}
Posted by: Guest on October-30-2019
6

Deleting an element from an array in PHP

$array = [0 => "a", 1 => "b", 2 => "c"];
unset($array[1]); //Key which you want to delete
/*
$array:
[
    [0] => a
    [2] => c
]
*/
//OR
$array = [0 => "a", 1 => "b", 2 => "c"];
array_splice($array, 1, 1);//Offset which you want to delet
/*
$array:
[
    [0] => a
    [1] => c
]
*/
Posted by: Guest on May-18-2020
0

php array remove keys keep values

<?php
$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));
?>
Array
(
    [0] => XL
    [1] => gold
)
Posted by: Guest on May-13-2020

Code answers related to "remove keys from array"

Browse Popular Code Answers by Language