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 = $this->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 GkNMt
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/OvlV0:6 Stack trace: #0 /in/OvlV0(22): getArrayFromHyphenArray(Array) #1 {main} thrown in /in/OvlV0 on line 6
Process exited with code 255.
Output for 5.3.21 - 5.6.28
Fatal error: Using $this when not in object context in /in/OvlV0 on line 6
Process exited with code 255.