0

I have a 2D array like this:

$cart = array(array("Item", 6.99), 
                     (array("Item 2", 13.99));

i am using this for a shopping cart i am making. I can add to it fine. What i need to be able to do is remove items from the array. I have been racking my brain trying to think of a way to do this and i've come up with nothing...

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by nav33n
0

this works when i remove the last item but if i try to remove anyothers the whole thing messes up. the items are not displayed but are still in an array. i cant explain it

0

In that case you might have to create a new array that excludes the element you want to delete, by slicing the original array (makes any sense)?

The php functions array_slice and array_merge should help.

0

simple.

<?php
$cart = array(array("Item", 6.99),(array("Item 2", 13.99)));  //$cart is a 2 dimensional array
print_r($cart); //print the contents of cart
unset($cart[0]); //unset 0th array element
print_r($cart); //print the cart
sort($cart); //sort the cart elements 
print_r($cart); //print sorted cart
?>

Thats it. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.