note 123945 added to function.array-key-last
| From: | rotexdegba007-githubatyahoodotca@php.net | Date: | Sun, 16 Jun 2019 04:54:31 +0000 |
| Subject: | note 123945 added to function.array-key-last | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211259@lists.php.net to get a copy of this message | ||
This polyfill works for PHP 5.6+.
It is a slight modification of "wes at nospam dot example dot org"'s example:
<?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; }
// the last 2 args to array_slice are crucial
return array_key_first(array_slice($array, -1, null, true));
}
}
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.34 (proxied: 2604:3d09:6e80:1c70:f586:c121:9f1f:8dea)
----
Manual Page -- http://php.net/manual/en/function.array-key-last.php
Edit -- https://master.php.net/note/edit/123945
Del: integrated -- https://master.php.net/note/delete/123945/integrated
Del: useless -- https://master.php.net/note/delete/123945/useless
Del: bad code -- https://master.php.net/note/delete/123945/bad+code
Del: spam -- https://master.php.net/note/delete/123945/spam
Del: non-english -- https://master.php.net/note/delete/123945/non-english
Del: in docs -- https://master.php.net/note/delete/123945/in+docs
Del: other reasons-- https://master.php.net/note/delete/123945
Reject -- https://master.php.net/note/reject/123945
Search -- https://master.php.net/manage/user-notes.php