Voting

: one minus zero?
(Example: nine)

The Note You're Voting On

rotexdegba007-github at yahoo dot ca
5 years ago
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));
}
}

<< Back to user notes page

To Top