3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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.1.0
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 hhvm-3.12.0
mallctl opt.prof: No such file or directory (2) Fatal error: request has exceeded memory limit in /in/ZAmgD on line 31
Process exited with code 255.
Output for hhvm-3.10.0
Fatal error: request has exceeded memory limit in /in/ZAmgD on line 31
Process exited with code 255.
Output for 5.4.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.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.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