3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getValues(&$egElement, $property, $option = NULL) { if(is_array($egElement) === FALSE) { return array(); } if(is_int($option) and $option > 1) { $values = array(); foreach($egElement as $key => $egSubElement) { $values = array_merge($values, getValues($egSubElement, $property, $option - 1)); } return $values; } $values = array(); foreach($egElement as $key => $eElement) { if(array_key_exists($property, $eElement)) { if(is_string($option)) { $values[$key] = call_user_func_array($option, array($eElement[$property])); } else if($option === TRUE) { $values[$key] = &$egElement[$key][$property]; } else { $values[$key] = $eElement[$property]; } } } reset($egElement); return $values; } $egElement = array(); for($i=0;$i<1000000;$i++) { $egElement[] = array('id' => (int)rand(0,100)); } $m = memory_get_usage(true); $mm = memory_get_peak_usage(true); $t = microtime(true); getValues($egElement, 'id'); echo "Memory: ".(memory_get_usage(true) - $m)." octets\n"; echo "Max Memory: ".(memory_get_peak_usage(true) - $mm)." octets\n"; echo "Time: ".(microtime(true) - $t)." secondes\n"; $m = memory_get_usage(true); $mm = memory_get_peak_usage(true); $t = microtime(true); array_column($egElement, 'id'); echo "Memory: ".(memory_get_usage(true) - $m)." octets\n"; echo "Max Memory: ".(memory_get_peak_usage(true) - $mm)." octets\n"; echo "Time: ".(microtime(true) - $t)." secondes\n";
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20480 bytes) in /in/ZAmgD on line 32
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.36, 5.6.0 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 72 bytes) in /in/ZAmgD on line 32
Process exited with code 255.
Output for 5.3.11 - 5.3.29
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in /in/ZAmgD on line 32
Process exited with code 255.
Output for 5.3.0 - 5.3.10
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /in/ZAmgD on line 32
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 24 bytes) in /in/ZAmgD on line 32
Process exited with code 255.
Output for 5.2.1 - 5.2.2
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 74 bytes) in /in/ZAmgD on line 32
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0
Fatal error: Call to undefined function memory_get_usage() in /in/ZAmgD on line 35
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: memory_get_usage() in /in/ZAmgD on line 35
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: memory_get_usage() in /in/ZAmgD on line 35
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: memory_get_usage() in /in/ZAmgD on line 35

preferences:
141.86 ms | 401 KiB | 224 Q