In PHP, array_key_first () gets the first key of an array however, it does not affect the internal array pointer. It was introduced in PHP 7.3.0.
Parameters
array
As has been noted. The parameter should be an array and it is compulsory.
Return Values
array_key_first( ) function returns the first key of the array. Moreover, if the array isn’t blank, otherwise, it’s null.
Example
$farray = [‘a’ => 1, ‘b’ => 2, ‘c’ => 3];
$fKey = array_key_first($farray);
var_dump($fKey);
?>
Output
string(1) “a”
Tip
There are many ways to explain this functionality for versions before PHP7.3.0. Also, It can be possible to use array_key(), however, that might be not efficient. This is possible to use key() and reset() as well however it might get change the internal array pointer. A perfect solution which doesn’t change the internal array pointer is mentioned below:
if (!function_exists(‘array_key_first’)) {
function array_key_first(array $arr) {
foreach($arr as $key => $unused) {
return $key;
}
return NULL;
}
}
?>
To know about the latest updates of PHP you can also visit here :
- COMPREHENSIVE REVIEW IS ON GUTENBERG BLOCK EDITOR, ELEMENTOR AND THE DIVI WEBPAGE BUILDER
- HERE’S THE NEW DIVI 4.0 THAT LETS YOU BUILD AND CUSTOMIZE A WEBPAGE AS PER YOUR REQUIREMENTS
- THE TOP 5 WAYS TO COLLECT CUSTOMER FEEDBACK
- Laravel 6.0 is Now Released. Let’s Discuss Deeply about this popular PHP Framework.
If you have any questions or queries you may also refer the website link from here
- DROPDOWN MENU NOT BEING DISPLAYED ON THE FIRST CLICK AFTER BEING CREATED DYNAMICALLY
- HOW TO COPY-PASTE HTML TO SUMMER NOTE
- WHY DOES NOT THE ANIMATION SPEED PARAMETER TAKE MY VARIABLE JQUERY
- CANNOT ABLE TO FETCH DATA FROM AJAX TO THE PHP PAGE
- SET DATE AND TIME IN JQUERY DATE AND TIME PICKER WITH SELENIUM