Re: Can someone explain this code snippet please?
| From: | Boa Constructor | Date: | Tue, 20 May 2003 17:03:24 +0000 |
| Subject: | Re: Can someone explain this code snippet please? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27928@lists.php.net to get a copy of this message | ||
Hey, thank you for your reply, that certainly helps. I think I'm going to
try using a foreach loop - fingers crossed it works!
Cheers,
Graeme :)
----- Original Message -----
From: "Daevid Vincent" <daevid@daevid.com>
To: <php-db@lists.php.net>
Sent: Monday, May 19, 2003 10:02 PM
Subject: RE: [PHP-DB] Can someone explain this code snippet please?
> It is looping through an associative array named $cart and mappping the
key
> to $isbn and the value to $qty.
>
> Then it checks if there is a variable named whatever the key/$isbn is. The
> $$ is the slickest thing ever. It lets you make a variable out of a
> variable.
>
> If said variable == 0 then it unsets the corresponding key/$isbn in the
> array $cart. Otherwise it is setting the same array key to the variable.
> Which seems kind of stupid to me since it should already be set, and it
> looks like they're setting the cart[isbn]'s value, not the key right? So
> that just looks wrong. They more likely wanted $cart[$isbn] = $qty
instead.
> But even that is dumb b/c the array's key would already have a qty
> associated with that isbn key.
>
>
>
> > -----Original Message-----
> > From: Boa Constructor [mailto:mickel@ntlworld.com]
> > Sent: Monday, May 19, 2003 12:59 PM
> > To: php-db@lists.php.net
> > Subject: [PHP-DB] Can someone explain this code snippet please?
> >
> >
> > Hey all, would someone be able to explain the following code
> > to me? I've
> > never used a foreach loop and I've never seen the "$$" before
> > a variable.
> >
> >
> > foreach ($cart as $isbn => $qty)
> > {
> > if($$isbn=="0")
> > unset($cart[$isbn]);
> > else
> > $cart[$isbn] = $$isbn;
> > }
> >
> >
> >
> > Cheers,
> >
> > Graeme :)
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>