I have an array that is created from a CSV file that I would like use the first value in each array as the key and combine the arrays with the same first value in an array. All arrays with [Parent] => top
should be combined into an array [top] => Array
. The below is a sample of what is in the CSV file. There is an unknown amount of MenuItem's. The only known is that the menus only go 3 levels deep Top>Sub1>Sub2. Also the MenuItems for the top menu can can change. I'm going to need something that can look at the [Parent] key in the first array and if it equals "top" then create an array based on the key [MenuItem], then any other array where [Parent]=Programs then that [MenuItem] & [URL] will be added to the Programs array.
Array
(
[0] => Array
(
[Parent] => top
[MenuItem] => Home
[URL] => /
)
[1] => Array
(
[Parent] => top
[MenuItem] => Programs
[URL] => /programs/
)
[2] => Array
(
[Parent] => Programs
[MenuItem] => Programs Sub1
[URL] => /programs/sub1/
)
[3] => Array
(
[Parent] => Programs
[MenuItem] => Programs Sub2
[URL] => /programs/sub2/
)
[4] => Array
(
[Parent] => Programs
[MenuItem] => Programs Sub3
[URL] => /programs/sub3/
)
)
Result should be:
Array
(
[top] => Array
(
[0] => Array
(
[MenuItem] => Home
[URL] => /
)
[1] => Array
(
[MenuItem] => Programs
[URL] => /programs/
[Programs] => Array
(
[0] => Array
(
[MenuItem] => Programs Sub1
[URL] => /programs/sub1/
)
[1] => Array
(
[MenuItem] => Programs Sub2
[URL] => /programs/sub2/
)
[2] => Array
(
[MenuItem] => Programs Sub3
[URL] => /programs/sub3/
)
)
Example of the Menu
Home Programs
Programs Sub1
Programs Sub2
Programs Sub3