Re: Removing specific array items



On 5/3/2012 9:25 AM, Scott Johnson wrote:
In a simple quote cart I track items in a session.

$_SESSION['quote'][##] = {data}

Which increments the ## for each added item.

At the time when the client wants to remove an item from the cart I just
clear the {data} from $_SESSION['quote'][item_id] = '';

The issue i run into is when I want to display the cart, i just cant
step thru the array without seeing if a particular item is '', which
works but would like to find a more 'elegant' way.

With all that said, is there a way to remove the item from the array
rather then clear the items data.

I can only think to
1. 'somehow' move or rotate the item to the end of the array and POP it off
2. or even go as far as step thru the array and create a new one with
only populated data items.

I have looked thru the 50+ different array functions and can't seem to
find the right tool. Maybe a combination I am not seeing.

Thanks
Scotty

unset().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Removing specific array items
    ... In a simple quote cart I track items in a session. ... At the time when the client wants to remove an item from the cart I just ... The issue i run into is when I want to display the cart, i just cant step thru the array without seeing if a particular item is '', which works but would like to find a more 'elegant' way. ... or even go as far as step thru the array and create a new one with only populated data items. ...
    (comp.lang.php)
  • trouble with arrays
    ... I'm trying to modify a shopping cart script from Mastering PHP/MySQL and am ... The original code, below, ... stores the cart items in a session variable array ...
    (comp.lang.php)
  • Re: "PHP and MySQL Web Development" by Luke Welling and Laura Thomson
    ... > adding something to the cart, and seeing the item in the cart, when then ... been supplanted, more recently, by the $_SESSION array. ... Look for "errata" for the book on the book publisher's website. ... Jeffrey D. Silverman | jeffrey AT jhu DOT edu ...
    (alt.php)
  • Re: Removing specific array items
    ... Which increments the ## for each added item. ... At the time when the client wants to remove an item from the cart I just clear the ... is there a way to remove the item from the array rather then ...
    (comp.lang.php)
  • Re: array type problem
    ... >> array and prints nothing. ... This works in as much as it displays the cart. ... when you run it the second time, even though there is only one item in the ... Andy ...
    (comp.lang.php)