How to Get First Element of Array in PHP?
Hey Developer,
In this example, you will learn php array get first element value. I explained simply step by step how to get first element of array in php. I explained simply step by step php get first key of array example. I would like to show you how to get first key value of array in php.
we will use array_shift() and array_values() function to get first element of array in php. so, let's see the simple code of it.
Example:
index.php
<?php
$myArray = ["One", "Two", "Three", "Four"];
$firstElem = array_shift(array_values($myArray));
var_dump($firstElem);
?>
Output:
string(3) "One"
I hope it can help you...