Hi,
I've got a script that lists the elements in an array (a shopping cart):
foreach($cart as $cart_item) {
$product_id = $cart_item->product_id;
$category = $cart_item->category;
etc etc
}
The above code allows me to index through the array but I wondered if there is a way of 'ordering' the results. I want to group the results by category.
So list all the elements from the array but, instead of them being listed in the order they are held in the array, I want to list them grouped together by category.
I hope I've made myself clear enough for you to help me. If you need more information then please let me know.
Many thanks if you can shed any light on how to go about this (or even if it is possible).
Cheers
John ;-)
I don't make mistakes, I'm merely beta-testing life.
I've got a script that lists the elements in an array (a shopping cart):
foreach($cart as $cart_item) {
$product_id = $cart_item->product_id;
$category = $cart_item->category;
etc etc
}
The above code allows me to index through the array but I wondered if there is a way of 'ordering' the results. I want to group the results by category.
So list all the elements from the array but, instead of them being listed in the order they are held in the array, I want to list them grouped together by category.
I hope I've made myself clear enough for you to help me. If you need more information then please let me know.
Many thanks if you can shed any light on how to go about this (or even if it is possible).
Cheers
John ;-)
I don't make mistakes, I'm merely beta-testing life.