3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * PHP Array key exists */ $n = 1000; // First a test with a empty array $array = array(); $time_start = microtime(true); $i = 0; while($i < $n){ $devnull = isset($array[$i++]); //var_dump($devnull); } $time_end = microtime(true); $time_while1= $time_end-$time_start; echo number_format($time_while1, 3, '.', '') ." seconds - isset(array[i]) on empty array \n"; $time_start = microtime(true); $i = 0; while($i < $n){ $devnull = array_key_exists($i++, $array); //var_dump($devnull); } $time_end = microtime(true); $time_while1= $time_end-$time_start; echo number_format($time_while1, 3, '.', '') ." seconds - array_key_exists(array,i) on empty array \n"; $time_start = microtime(true); $i = 0; while($i < $n){ $devnull = (bool)@$array[$i++]; //var_dump($devnull); } $time_end = microtime(true); $time_while1= $time_end-$time_start; echo number_format($time_while1, 3, '.', '') ." seconds - cast array[i] on empty array \n"; // Create test array $i = 0; $array = array(); while($i < $n) { $array[$i++] = true; } $time_start = microtime(true); $i = 0; while($i < $n){ $devnull = isset($array[$i++]); //var_dump($devnull); } $time_end = microtime(true); $time_while1= $time_end-$time_start; echo number_format($time_while1, 3, '.', '') ." seconds - isset(array[i]) on full array \n"; $time_start = microtime(true); $i = 0; while($i < $n){ $devnull = array_key_exists($i++, $array); //var_dump($devnull); } $time_end = microtime(true); $time_while1= $time_end-$time_start; echo number_format($time_while1, 3, '.', '') ." seconds - array_key_exists(array,i) on full array \n"; $time_start = microtime(true); $i = 0; while($i < $n){ $devnull = (bool)@$array[$i++]; //var_dump($devnull); } $time_end = microtime(true); $time_while1= $time_end-$time_start; echo number_format($time_while1, 3, '.', '') ." seconds - cast array[i] on full array \n"; ?>
Output for 5.1.0 - 5.1.5, 5.2.2 - 5.2.16, 5.3.0 - 5.3.16, 5.3.18 - 5.3.29, 5.4.0 - 5.4.7, 5.4.9 - 5.4.45, 5.5.24 - 5.5.35, 5.6.9 - 5.6.21, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.0
0.000 seconds - isset(array[i]) on empty array 0.000 seconds - array_key_exists(array,i) on empty array 0.000 seconds - cast array[i] on empty array 0.000 seconds - isset(array[i]) on full array 0.000 seconds - array_key_exists(array,i) on full array 0.000 seconds - cast array[i] on full array
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.6, 4.4.8 - 4.4.9, 5.0.0 - 5.0.5, 5.1.6, 5.2.17, 5.3.17, 5.4.8, 5.6.8, 5.6.28
0.000 seconds - isset(array[i]) on empty array 0.000 seconds - array_key_exists(array,i) on empty array 0.001 seconds - cast array[i] on empty array 0.000 seconds - isset(array[i]) on full array 0.000 seconds - array_key_exists(array,i) on full array 0.000 seconds - cast array[i] on full array
Output for 4.4.7, 5.2.0 - 5.2.1
0.000 seconds - isset(array[i]) on empty array 0.000 seconds - array_key_exists(array,i) on empty array 0.001 seconds - cast array[i] on empty array 0.000 seconds - isset(array[i]) on full array 0.000 seconds - array_key_exists(array,i) on full array 0.001 seconds - cast array[i] on full array

preferences:
134.12 ms | 402 KiB | 174 Q