3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $data = array('one' => array( 'two' => 3, 'four' => array(5,6,7)),'eight' => array( 'nine'=> array('ten' =>11))); function array_to_value($akey,$val) { $array_key = array(); if(is_array($val)) { foreach($val as $key => $value) { if($akey != '') { $pkey = $akey.'/'.$key; } else { $pkey = $key; } if(is_array($value)) { $array_key = array_to_value($pkey,$value); } $array_key[$pkey] = $value; } return $array_key; } } print_r(array_to_value('',$data)); print_r($data);
Output for 4.3.0 - 7.1.0
Array ( [eight/nine/ten] => 11 [eight/nine] => Array ( [ten] => 11 ) [eight] => Array ( [nine] => Array ( [ten] => 11 ) ) ) Array ( [one] => Array ( [two] => 3 [four] => Array ( [0] => 5 [1] => 6 [2] => 7 ) ) [eight] => Array ( [nine] => Array ( [ten] => 11 ) ) )