Re: Splitting Vars from MySQL in PHP

From: Date: Sun, 01 May 2005 20:12:43 +0000
Subject: Re: Splitting Vars from MySQL in PHP
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-214295@lists.php.net to get a copy of this message
On Sat, April 30, 2005 8:16 pm, Rasmus Lerdorf said: >> php -a >> <?php >> $foo = array('a'=>'apple', 'b'=>'banana', >> 'c'=>'coconut'); >> while (list($k, $v) = each($foo)){ >> echo "$k: $v\n"; >> } >> ?> >> Content-type: text/html >> X-Powered-By: PHP/4.3.11 >> >> a: apple >> b: banana >> c: coconut >> >> It has worked just fine with alpha indices since PHP 3.0rc2, at a >> minimum, >> cuz I've been doing it that long. >> >> I dunno who was smoking what that day they typed the documentation :-) >> >> I'm pretty sure it's not an "undocumented feature" that it works. > > Richard, this is what the docs are talking about: > > list($a,$b,$c,$d) = array('a','b','c','d'); > echo $a,$b,$c,$d; > > vs. > > list($a,$b,$c,$d) = > array('a'=>'a','b'=>'b','c'=>'c','d'=>'d'); > echo $a,$b,$c,$d; > > In your case you are calling each() which itself returns a numerically > indexed array. I realized how stupid my post was about 30 seconds after sending it. I plead sleep deprivation :-) The correct answer, of course, was http://php.net/extract -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#214295) next »