array ( 'b1' => array ( 'c1' => 1, 'c2' => 2, 'c3' => 3, ), 'b2' => array ( 'c' => 4, ), ), ); $target = array ( 'a/b1/c1' => 1, 'a/b1/c2' => 2, 'a/b1/c3' => 3, 'a/b2/c' => 4, ); function dump($a) { foreach($a as $path => $value) { echo "$path => $value\r\n"; } } function pathjoin_help($o, $elms, &$res) { if(is_int($o)) { $res[implode('/', $elms)] = $o; } else if(is_array($o)) { $elms[] = null; foreach($o as $pathelm => $value) { $elms[count($elms)-1] = $pathelm; pathjoin_help($value, $elms, $res); } } else { die("Houston we have a problem"); } } function pathjoin($a) { $res = array(); pathjoin_help($a, array(), $res); return $res; } $output = pathjoin($input); dump($output); dump($target); print_r( pathjoin( array ( 'a' => array ( 'b1' => array ( 'c1' => '1', 'c2' => 2, 'c3' => 3, ), 'b2' => array ( 'c' => 4, ), ), ) ) ); ?>