RE: Can someone explain this code snippet please?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:  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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux