3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getArrayFromHyphenArray($flatArray){ $deepArray = array(); foreach($flatArray as $key => $value){ $keysArray = explode('-', $key); var_dump($keysArray); $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])){ var_dump($key); $array[$key] = array(); } return recursiveSet($array[$key],$arg,$value); } $arra = array('this-is-some' => 'value', 'this-is-second' => 'value'); print_r(getArrayFromHyphenArray($arra));
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { [0]=> string(4) "this" [1]=> string(2) "is" [2]=> string(4) "some" } string(4) "this" string(2) "is" string(4) "some" array(3) { [0]=> string(4) "this" [1]=> string(2) "is" [2]=> string(6) "second" } string(4) "this" Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/tq8YY:18 Stack trace: #0 /in/tq8YY(7): recursiveSet('value', Array, 'value') #1 /in/tq8YY(24): getArrayFromHyphenArray(Array) #2 {main} thrown in /in/tq8YY on line 18
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.81 ms | 402 KiB | 8 Q