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
Output for 7.0.4, 7.1.3 - 7.1.4, 7.1.10 - 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 5.6.1, 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
Output for hhvm-3.15.4
0.000001.4 0.000001.4 0.000002.4 0.000004.4
Output for 5.6.3, 5.6.30
0.000004.4 0.000001.4 0.000004.4 0.000004.4
Output for 5.6.6, 5.6.13, 5.6.17, 5.6.21, 5.6.23 - 5.6.24, 5.6.27 - 5.6.29
0.000002.4 0.000001.4 0.000002.4 0.000002.4
Output for 5.6.26
0.000002.4 0.000001.4 0.000004.4 0.000002.4
Output for 5.6.25
0.000003.4 0.000001.4 0.000002.4 0.000003.4
Output for 5.6.22
0.000003.4 0.000001.4 0.000004.4 0.000002.4
Output for 5.6.20
0.000002.4 0.000001.4 0.000004.4 0.000004.4
Output for 5.6.19
0.000004.4 0.000001.4 0.000002.4 0.000002.4
Output for 5.6.18
0.000005.4 0.000002.4 0.000004.4 0.000005.4
Output for 5.6.16
0.000005.4 0.000001.4 0.000003.4 0.000004.4
Output for 5.6.15
0.000002.4 0.000000.4 0.000001.4 0.000003.4
Output for 5.6.14
0.000002.4 0.000001.4 0.000002.4 0.000001.4
Output for 5.6.12
0.000002.4 0.000001.4 0.000004.4 0.000003.4
Output for 5.6.11
0.000004.4 0.000001.4 0.000003.4 0.000002.4
Output for 5.6.10
0.000003.4 0.000002.4 0.000004.4 0.000004.4
Output for 5.6.9
0.000003.4 0.000001.4 0.000003.4 0.000003.4
Output for 5.6.8
0.000003.4 0.000001.4 0.000003.4 0.000004.4
Output for 5.6.7
0.000004.4 0.000001.4 0.000003.4 0.000004.4
Output for 5.6.5
0.000002.4 0.000002.4 0.000004.4 0.000003.4
Output for 5.6.4
0.000004.4 0.000001.4 0.000002.4 0.000003.4
Output for 5.6.2
0.000003.4 0.000001.4 0.000002.4 0.000004.4
Output for 5.6.0
0.000003.4 0.000002.4 0.000004.4 0.000003.4