3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getArrayFromHyphenArray($flatArray){ $deepArray = array(); foreach($flatArray as $key => $value){ $keysArray = explode('-', $key); $deepArray = recursiveSet($deepArray, $keysArray, $value); } } function recursiveSet(&$array, $arg, $value){ if(empty($arg)){ $array = $value; return $array; } $key = array_shift($arg); if(!isset($array[$key])){ $array[$key] = array(); } return recursiveSet($array[$key],$arg,$value); } $arra = array('this-is-some' => 'value', 'this-is-second' => 'value'); print_r(getArrayFromHyphenArray($arra));
based on OvlV0
Output for 7.0.0 - 7.2.0
Warning: Illegal string offset 'this' in /in/gkT1T on line 16 Notice: Array to string conversion in /in/gkT1T on line 16 Warning: Illegal string offset 'this' in /in/gkT1T on line 18 Fatal error: Uncaught Error: Only variables can be passed by reference in /in/gkT1T:18 Stack trace: #0 /in/gkT1T(6): recursiveSet('Aalue', Array, 'value') #1 /in/gkT1T(22): getArrayFromHyphenArray(Array) #2 {main} thrown in /in/gkT1T on line 18
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Warning: Illegal string offset 'this' in /in/gkT1T on line 16 Notice: Array to string conversion in /in/gkT1T on line 16 Warning: Illegal string offset 'this' in /in/gkT1T on line 18 Fatal error: Only variables can be passed by reference in /in/gkT1T on line 18
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Fatal error: Only variables can be passed by reference in /in/gkT1T on line 18
Process exited with code 255.