Re: Silly varible question
| From: | Jochem Maas | Date: | Thu, 13 Jul 2006 12:33:24 +0000 |
| Subject: | Re: Silly varible question | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-239408@lists.php.net to get a copy of this message | ||
Brad Bonkoski wrote:
> Why not just have another array...
>
> $bag = array();
> $item[] ....
>
> array_push($bag, $item);
>
> then store the bag in the session.
> so, you would have count($bag) items in your shopping cart, and you
> would be able to easily access them.
> Just a thought, instead of munging variable names.
>
> -B
>
use the $_SESSION super global instead of using session_register()
(read the manual for the fine print regarding $_SESSION and why
session_register() is no longer recommended)
e.g.:
function addItemToBag($item)
{
if (!isset($_SESSION['bag'])) $_SESSION['bag'] = array();
$_SESSION['bag'][] = $item;
}
>>
>> session_register('item');
>>
>> In the session the item is known as 'item'. What I need for it to be is
>> 'item1' so when the customer chooses another product I can increase
>> $count
>> by 1 and have the next array with values stored as 'item2'.
>>
>> Thanks for any help,
>>
>> Ed
>>
>>
>>
>