3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 标准array $array = array(1024 * 1024); // array(); for ($i = 0; $i < 1024 * 1024; ++$i) $array[$i] = 0; print_r('Standard array: '.memory_get_peak_usage()); // spl $array = new SplFixedArray(1024 * 1024); // array(); for ($i = 0; $i < 1024 * 1024; ++$i) $array[$i] = 0; print_r('SplFixedArray: '.memory_get_peak_usage());
Output for 8.3.5 - 8.3.6
Standard array: 17169848SplFixedArray: 33947216
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Standard array: 17169848 Fatal error: Out of memory (allocated 18878464 bytes) (tried to allocate 16777216 bytes) in /in/A3c9u on line 10 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.2.18
Standard array: 17169848SplFixedArray: 33947200
Output for 8.1.28
Standard array: 33947536SplFixedArray: 50724888
Output for 8.1.2 - 8.1.27
Fatal error: Out of memory (allocated 18878464) (tried to allocate 33554440 bytes) in /in/A3c9u on line 5 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for 8.1.0 - 8.1.1
Standard array: 33947536SplFixedArray: 50724872
Output for 8.0.17 - 8.0.30
Standard array: 33946880SplFixedArray: 50724264
Output for 8.0.0 - 8.0.16
Standard array: 33946880SplFixedArray: 50724248
Output for 7.4.0 - 7.4.33
Standard array: 33947184SplFixedArray: 50724568
Output for 7.3.0 - 7.3.33
Standard array: 33947088SplFixedArray: 50724472
Output for 7.2.17 - 7.2.33
Standard array: 33943016SplFixedArray: 50720400
Output for 7.2.0 - 7.2.6
Standard array: 33943056SplFixedArray: 50720440
Output for 7.1.26 - 7.1.33
Standard array: 33906344SplFixedArray: 50683728
Output for 7.1.0, 7.1.7 - 7.1.20
Standard array: 33906416SplFixedArray: 50683800
Output for 7.1.5 - 7.1.6
Standard array: 33906656SplFixedArray: 50684040
Output for 7.0.0 - 7.0.20
Standard array: 33906448SplFixedArray: 50683848
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in /in/A3c9u on line 5
Process exited with code 255.

preferences:
181.39 ms | 402 KiB | 213 Q