PHP

PHP Get First Element of Associative Array1 min read

You can use the PHP array_shift() function remove the first element from an array in PHP. The array_shift() function returns the first value of the array. If array is empty or is not an array then NULL will be returned.

You can use the PHP reset and key functions remove the First Element of Associative from an array in PHP.
reset(), set the internal pointer of an array to its first element.
key() fetch a key from an array.




First let’s see the $array output :

Output:

Now we will use PHP reset() and key() functions to Get First Element of an Associative array like in below example

Output:

Leave a Comment