Help regrouping an array
- by jim
I'd like to regroup my array. I have the following:
Array
(
[0] => Array
(
[name] => test1
[item_id] => 1
[category] => cat1
)
[1] => Array
(
[name] => test2
[item_id] => 2
[category] => cat1
)
[2] => Array
(
[name] => test3
[item_id] => 3
[category] => cat1
)
[3] => Array
(
[name] => test4
[item_id] => 4
[category] => cat2
)
)
I'd like to regroup it like this:
Array
(
[cat1] => Array
(
[0] => Array
(
[name] => test1
[item_id] => 1
)
[1] => Array
(
[name] => test2
[item_id] => 2
)
[2] => Array
(
[name] => test3
[item_id] => 3
)
)
[cat2] => Array
(
[name] => test4
[item_id] => 4
)
)
Can someone tell me how this is best done?