note 123767 deleted from function.array-key-first by cmb

From: Date: Wed, 08 May 2019 09:50:07 +0000
Subject: note 123767 deleted from function.array-key-first by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210987@lists.php.net to get a copy of this message
Note Submitter: devonblzx ---- 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]; } }

« previous php.notes (#210987) next »