How to remove 0 index key from result in php?

by haylee.mertz , in category: PHP General , 2 months ago

How to remove 0 index key from result in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , 2 months ago

@haylee.mertz 

You can remove the 0 index key from an array in PHP using the unset() function. Here is an example code snippet to demonstrate how to remove the 0 index key from a result array:

1
2
3
4
5
$result = array("zero", "one", "two", "three");

unset($result[0]);

print_r($result);


This code snippet will output the following result:

1
2
3
4
5
6
Array
(
    [1] => one
    [2] => two
    [3] => three
)


As you can see, the 0 index key has been removed from the result array.