3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function array_unflatten($array) { $final = array(); foreach($array as $keychain => $value) { $segment = array(); $tmp = &$segment; $keys = preg_split('!(!<\\)/!', $keychain); foreach($keys as $key) { $tmp = &$tmp[$key] = array(); } $tmp = $value; $final = array_merge($final, $segment); } return $final; } function array_flatten($array, $keychain = '/', $data = '') { if (!is_array($data)) $data = array(); foreach($array as $key=> $value) { if(is_array($value)) { $data = array_merge($data, array_flatten($value, $keychain.$key.'/')); } else { $data[$keychain.$key] = $value; } } return $data; } $array = array( array( 'foo' => 'bar', 'baz' => 'blah' ), array( 'foo' => 'bar', 'baz' => 'blah' ) ); $flat = array_flatten($array); var_dump($flat, array_unflatten($flat));
Output for 5.3.0 - 5.4.8
Parse error: syntax error, unexpected '=' in /in/sTGts on line 12
Process exited with code 255.