I have the following array :
$array = [
'2' => ['3' => ['56' => '2'], '6' => ['48' => '2']],
'4' => ['4' => ['433' => '2', '140' => '2'], '8' => ['421' => '2', '140' => '2']],
'5' => ['5' => ['88' => '4', '87' => '2']]
];
The following code (flattening) should return it by preserving keys, but it doesnt?
collect($array)->flatten(1);
should give me
[
'3' => ['56' => '2'],
'6' => ['48' => '2'],
'4' => ['433' => '2', '140' => '2'],
'8' => ['421' => '2', '140' => '2'],
'5' => ['88' => '4', '87' => '2']
]
However it loses the keys, and just gives array results :/ Am I using it wrong? How should I flatten and preserve keys?
flatten
supports maintaining keys - how would you expect it to work if the keys in a lower level weren't unique? – Elbertina