Try reading the PHP Manual section on foreach() loops, too. I think it's fairly helpful in getting your head around the concept. http://www.php.net/manual/en/control-structures.foreach.php Edward Dudlik Becoming Digital www.becomingdigital.com ----- Original Message ----- From: "Boa Constructor" <mickel@ntlworld.com> To: <php-db@lists.php.net> Sent: Tuesday, 20 May, 2003 13:03 Subject: Re: Can someone explain this code snippet please? 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: 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: 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 > -- 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