This example will teach you how to retrieve the first element of an array in PHP. I simply walked you through the process of getting the first element of an array in PHP. I simply provided an example of how to use php to fetch the first key of an array. I would like to demonstrate how to retrieve the first key value from an array in PHP.
To retrieve the first element of an array in PHP, we will utilize the array_shift() and array_values() functions. So let us look at the short code for it.
Eaxmple
<?php
$myArray = ["One", "Two", "Three", "Four"];
$firstElem = array_shift(array_values($myArray));
var_dump($firstElem);
?>
OutPut:
string(3) "One"