3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array_fill(0, 100000, true); function is_indexed_foreach($array) { $n = 0; foreach ($array as $key => $_) { if ($key !== $n++) { return false; } } return true; } function is_indexed_range($array) { return array_keys($array) === range(0, count($array) - 1); } printf("%.2f mb\n", memory_get_peak_usage() / 1024 / 1024); is_indexed_foreach($array); printf("%.2f mb\n", memory_get_peak_usage() / 1024 / 1024); is_indexed_range($array); printf("%.2f mb\n", memory_get_peak_usage() / 1024 / 1024);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
2.38 mb 2.38 mb 6.38 mb
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 2.38 mb 2.38 mb 6.38 mb
Output for 7.3.0 - 7.3.33, 8.1.0 - 8.1.28
4.38 mb 4.38 mb 12.38 mb
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
4.37 mb 4.38 mb 12.38 mb
Output for 7.2.0 - 7.2.34
4.37 mb 4.37 mb 12.38 mb

preferences:
191.72 ms | 401 KiB | 184 Q