3v4l.org

run code in 300+ PHP versions simultaneously
<?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; }
Output for 7.0.4, 7.1.3 - 7.1.4, 7.1.10, 7.2.0 - 7.2.6
0.000000.4 0.000000.4 0.000000.4 0.000000.4
Output for 7.0.2, 7.0.19, 7.1.7
0.000001.4 0.000001.4 0.000001.4 0.000001.4
Output for 7.0.20, 7.1.6
0.000002.4 0.000001.4 0.000001.4 0.000001.4
Output for 7.0.5, 7.0.7 - 7.0.8, 7.0.12 - 7.0.16, 7.0.18, 7.1.0 - 7.1.2, 7.1.5
0.000001.4 0.000000.4 0.000001.4 0.000001.4
Output for 7.0.17
0.000002.4 0.000000.4 0.000001.4 0.000001.4
Output for 7.0.11
0.000001.4 0.000001.4 0.000002.4 0.000002.4
Output for 7.0.1, 7.0.10
0.000001.4 0.000000.4 0.000002.4 0.000001.4
Output for 7.0.9
0.000002.4 0.000001.4 0.000001.4 0.000002.4
Output for 7.0.6
0.000001.4 0.000000.4 0.000001.4 0.000002.4
Output for 7.0.3
0.000000.4 0.000000.4 0.000000.4 0.000001.4
Output for 7.0.0
0.000000.4 0.000000.4 0.000001.4 0.000000.4

preferences:
66.99 ms | 401 KiB | 37 Q