note 123836 added to function.array-key-last
| From: | wes at nospam dot example dot org | Date: | Thu, 09 May 2019 21:37:40 +0000 |
| Subject: | note 123836 added to function.array-key-last | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210999@lists.php.net to get a copy of this message | ||
Correct polyfill (one that doesn't make copies of arrays, and that doesn't make use of the
IAP) is:
<?php
if(!function_exists('array_key_first')){
function array_key_first(array $array){
if($array === []){
return NULL;
}
foreach($array as $key => $_) return $key;
}
}
if(!function_exists('array_key_last')){
function array_key_last(array $array){
if($array === []){
return NULL;
}
return array_key_first(array_slice($array, -1));
}
}
?>
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.142 (proxied: 79.31.59.76)
----
Manual Page -- http://php.net/manual/en/function.array-key-last.php
Edit -- https://master.php.net/note/edit/123836
Del: integrated -- https://master.php.net/note/delete/123836/integrated
Del: useless -- https://master.php.net/note/delete/123836/useless
Del: bad code -- https://master.php.net/note/delete/123836/bad+code
Del: spam -- https://master.php.net/note/delete/123836/spam
Del: non-english -- https://master.php.net/note/delete/123836/non-english
Del: in docs -- https://master.php.net/note/delete/123836/in+docs
Del: other reasons-- https://master.php.net/note/delete/123836
Reject -- https://master.php.net/note/reject/123836
Search -- https://master.php.net/manage/user-notes.php