Getting the first element of an array in PHP
In this tutorial, we are going to learn about how to get the first element of an array in PHP.
Getting the first element
To get the first element of an array, we can use the built-in reset()
function in PHP.
Here is an example:
$arr=array("lion", "tiger", "cat");
$firstElement=reset($arr);
echo $firstElement;
Output:
"lion"
Note: The reset() function rewinds the array’s internal pointer to the first element and returns the value of it.