I have this Array:
$input_array = array(
'one' => array(
'two' => '3',
'four' => array(5,6,7)
),
'eight' => array(
'nine' => array(
'ten' => '11'
)
)
);
I want the output to be:
one/two:3
one/four/0:5
one/four/1:6
one/four/2:7
eight/nine/ten:11
I have managed to make this function/code:
function flatten($array) {
if (is_array($array)) {
//get the key and value pair of the array
foreach ($array as $key => $value) {
if (is_array($value)) {
echo $key.'/';
} else {
echo $key.":".$value."<br/>\n";
}
flatten($value);
}
} else {
return false;
}
}
flatten($input_array);
Currently it outputs:
one/two:3
four/0:5
1:6
2:7
eight/nine/ten:11
The 1st and last line are correct, but in the middle it's not the output I wanted, I know I am close, just need more modification. Anyone can help? Thanks!