I know this is a simple question, and one that has certainly been asked but my googlefu is seriously failing me here and I'm drowning.
I have an array of values like so
array(
array(topCat: "1", secondCat: "1", listItem: "List Item 1"),
array(topCat: "1", secondCat: "1", listItem: "List Item 2"),
array(topCat: "1", secondCat: "2", listItem: "List Item 1"),
array(topCat: "1", secondCat: "3", listItem: "List Item 2"),
array(topCat: "2", secondCat: "1", listItem: "List Item 1")) etc etc
I need it to be like this:
array(
array(topCat: 1, secondCat: 2, array("list item 1", "List Item 2"))).
One of my searches gave me this:
$newArray = array();
foreach ($oldArray as $row){
$newArray[$row['topCat']][$row['secondCat']][] = $row['listItem'];
}
And that almost works except it assigns the key to the value so it becomes array(1, 2: array())
Which isn't what I want.
I need to loop over the values and assign those as keys, how do I do this in PHP?
In the end the array needs to have 3 dimensions, topCat which would contain all of the second categories, secondCat which would contain all of the list items.