note 123767 added to function.array-key-first
| From: | devonblzx@php.net | Date: | Wed, 10 Apr 2019 17:55:46 +0000 |
| Subject: | note 123767 added to function.array-key-first | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210585@lists.php.net to get a copy of this message | ||
Since the other notes for polyfills did not account for the internal pointer, empty arrays, or
pre-PHP7, this polyfill should work reliably for all PHP5 and PHP7 versions:
<?php
if (!function_exists('array_key_first')) {
/**
* Gets the first key of an array
*
* @param array $array
* @return mixed
*/
function array_key_first($array)
{
if (!is_array($array) || !count($array)) {
return null;
}
$keys = array_keys($array);
return $keys[0];
}
}
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.34 (proxied: 24.236.137.192)
----
Manual Page -- http://php.net/manual/en/function.array-key-first.php
Edit -- https://master.php.net/note/edit/123767
Del: integrated -- https://master.php.net/note/delete/123767/integrated
Del: useless -- https://master.php.net/note/delete/123767/useless
Del: bad code -- https://master.php.net/note/delete/123767/bad+code
Del: spam -- https://master.php.net/note/delete/123767/spam
Del: non-english -- https://master.php.net/note/delete/123767/non-english
Del: in docs -- https://master.php.net/note/delete/123767/in+docs
Del: other reasons-- https://master.php.net/note/delete/123767
Reject -- https://master.php.net/note/reject/123767
Search -- https://master.php.net/manage/user-notes.php