remove an item from inside an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkawamoto
Forum Newbie
Posts: 1
Joined: Tue Dec 16, 2003 1:05 pm

remove an item from inside an array

Post by kkawamoto »

I'm new to PHP and am working on a shopping cart that I'm doing for my final project and we are instructed to do this using arrays. We are use array_push to put the item we are adding at the end of the array which I already have done but the problem I'm running into is removing the cart item from the array. Following the instructions I have to remove an item from an array: how do I change the value of the item I wish to delete within the array to "z" so I can use array_pop to remove it? Any advice would be helpful.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

I hope [php_man]array_filter[/php_man]() can help you on this matter.

Cheers,
Scorphus.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

You might also take a look at
array_splice()

ps : php manual is very helpful : http://ca.php.net/manual/en/function.array-splice.php
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

wow over my head a bit
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can use the index of the element and just [php_man]unset[/php_man]() it.

Mac
Post Reply