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){ 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
string(4) "this" string(2) "is" string(4) "some" string(4) "this" Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/JppQn:17 Stack trace: #0 /in/JppQn(6): recursiveSet('value', Array, 'value') #1 /in/JppQn(23): getArrayFromHyphenArray(Array) #2 {main} thrown in /in/JppQn on line 17
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:
49.47 ms | 401 KiB | 8 Q