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; } if( is_string($option) or $option === TRUE ) { $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]; } } } reset($egElement); } else { return array_column($egElement, $property); } return $values; } $eg = array( 1 => array('id' => 4, 'dragon' => array('toto' => 5, 'titi' => 6)), 2 => array('id' => 5, 'dragon' => array('toto' => 5, 'titi' => 6)), 3 => array('id' => 6, 'dragon' => array('toto' => 5, 'titi' => 6)), 4 => array('id' => 7, 'dragon' => array('toto' => 5, 'titi' => 6)), 5 => array('id' => 8, 'dragon' => array('toto' => 5, 'titi' => 6)), 6 => array('id' => 9, 'dragon' => array('toto' => 5, 'titi' => 6)), 7 => array('id' => 10, 'dragon' => array('toto' => 5, 'titi' => 6)), 8 => array('id' => 11, 'dragon' => array('toto' => 5, 'titi' => 6)), ); var_dump(getValues($eg));
Output for 7.1.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function getValues(), 1 passed in /in/0Z6UY on line 63 and at least 2 expected in /in/0Z6UY:3 Stack trace: #0 /in/0Z6UY(63): getValues(Array) #1 {main} thrown in /in/0Z6UY on line 3
Process exited with code 255.
Output for 5.5.0 - 7.0.14
Warning: Missing argument 2 for getValues(), called in /in/0Z6UY on line 63 and defined in /in/0Z6UY on line 3 Notice: Undefined variable: property in /in/0Z6UY on line 45 array(8) { [0]=> array(2) { ["id"]=> int(4) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } [1]=> array(2) { ["id"]=> int(5) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } [2]=> array(2) { ["id"]=> int(6) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } [3]=> array(2) { ["id"]=> int(7) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } [4]=> array(2) { ["id"]=> int(8) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } [5]=> array(2) { ["id"]=> int(9) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } [6]=> array(2) { ["id"]=> int(10) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } [7]=> array(2) { ["id"]=> int(11) ["dragon"]=> array(2) { ["toto"]=> int(5) ["titi"]=> int(6) } } }
Output for 5.1.0 - 5.4.45
Warning: Missing argument 2 for getValues(), called in /in/0Z6UY on line 63 and defined in /in/0Z6UY on line 3 Fatal error: Call to undefined function array_column() in /in/0Z6UY on line 45
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Missing argument 2 for getValues() in /in/0Z6UY on line 3 Fatal error: Call to undefined function array_column() in /in/0Z6UY on line 45
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Warning: Missing argument 2 for getvalues() in /in/0Z6UY on line 3 Fatal error: Call to undefined function: array_column() in /in/0Z6UY on line 45
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Warning: Missing argument 2 for getvalues() in /in/0Z6UY on line 3 Fatal error: Call to undefined function: array_column() in /in/0Z6UY on line 45
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Missing argument 2 for getvalues() in /in/0Z6UY on line 3 Fatal error: Call to undefined function: array_column() in /in/0Z6UY on line 45