How to get first element of array in php?
There are various methods in PHP to get the first element of an array. Some of the techniques are the use of reset function, array_slice function, array_reverse, array_values, foreach loop, etc.
BY Best Interview Question ON 15 Apr 2020
Example
Suppose we have an array like
$arrayVar = array('best', 'interview', 'question', 'com');
1. With direct accessing the 0th index:
echo $arrayVar[0];
2. With the help of reset()
echo reset($arrayVar);
3. With the help of foreach loop
foreach($arrayVar as $val) {
echo $val;
break; // exit from loop
}