3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getArrayFromHyphenArray($flatArray){ $deepArray = array(); foreach($flatArray as $key => $value){ $keysArray = explode('-', $key); $deepArray = recursiveSet($deepArray, $keysArray, $value); } } function recursiveSet(&$array, &$arg, $value){ static $count = 0; if(empty($arg)){ $array = $value; return $array; } $key = array_shift($arg); if(!isset($array[$key])){ print_r($key); $count++; echo $count; $array[$key] = array(); } return recursiveSet($array[$key],$arg,$value); } $flatArray = array('this-is-something' => 'value1', 'bif-is-else' => 'value3', 'this-different-else' => 'value2'); print_r(getArrayFromHyphenArray($flatArray));
Output for git.master, git.master_jit, rfc.property-hooks
this1is2something3bif4 Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/v2iiH:21 Stack trace: #0 /in/v2iiH(6): recursiveSet('value1', Array, 'value3') #1 /in/v2iiH(27): getArrayFromHyphenArray(Array) #2 {main} thrown in /in/v2iiH on line 21
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:
40.5 ms | 401 KiB | 8 Q