3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php 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' ) ); var_dump(array_flatten($array));
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(4) { ["/0/foo"]=> string(3) "bar" ["/0/baz"]=> string(4) "blah" ["/1/foo"]=> string(3) "bar" ["/1/baz"]=> string(4) "blah" }