Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Removing specific array items
- Scott Johnson
May 3, 2012, 1:25 pm
rate this thread
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 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.
- Thomas 'PointedEars' Lahn
May 3, 2012, 4:05 pm
Re: Removing specific array items
Scott Johnson wrote:
ISTM you are looking for
$_SESSION['quote'] = $data;
instead, which automatically increments the index of the item in
$_SESSION['quote']. On the other hand, if the real code was
$_SESSION['quote'][$index] = $items[$index];
you might want to consider simplifying the loop to one statement:
$_SESSION['quote'] = $items;
(Please try to work on your spelling.)
After the above, you might want to use
/* Item with $item_id exists */
This approach is more precise in combination with is_null().
That is _not_ a question.
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann