High All
I need help with the following array issue.
I build a shopping cart array which would look like this when printed on screen:
Array
(
[1] => Array // Product ID Level
(
[3] => Array // Product Colour ID Level
(
[quantity] => 1
[productprice] => 8.99
[productsize] => small
[productcolour] => 3
)
[1] => Array
(
[quantity] => 1
[productprice] => 8.99
[productsize] => small
[productcolour] => 1
)
)
[2] => Array
(
[3] => Array
(
[quantity] => 1
[productprice] => 8.99
[productsize] => onesize
[productcolour] => 3
)
)
)
The first key is the Product ID and the array within this key is the product colour id (thus allowing me to have different colour items of the same product ID in the array).
My issue is when I come to delete items from the basket.
I am currently deleting using this method when I tick checkboxes and submit my form:
foreach($deleteitems as $newkey => $newval) {
list($prodid, $colourid) = explode('|', $newval);
unset($_SESSION['cart'][$prodid][$colourid]);
}
Whilst this does actually remove the product from the array based on the Colour ID, it DOES NOT remove the PRODUCT ID level from the array if all colours of one product have been deleted - does that make sense?
So basically i need help on checking of there is only one colour id of a product id left in the array, and if I delete it, it also deletes the Product ID level of the array.
Thanks for reading.