3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $funcs = [ function ($array) { end($array); $key = key($array); reset($array); return $key; }, function ($array) { return count($array) - 1; }, function ($array) { return key(array_slice($array,-1,1,true)); }, function ($array) { $keys = array_keys($array); return end($keys); } ]; $test = ['a', 'b', 'c', 'd', 'e']; foreach ($funcs as $f) { $results = []; for ($i = 0; $i < 10000; $i++) { $start_time = microtime(TRUE); $f($test); $end_time = microtime(TRUE); $results[] = $end_time - $start_time; } echo sprintf('%f.4', array_sum($results) / count($results)) . PHP_EOL; }
based on fkf2R