Re: Arrays

From: Date: Mon, 31 Jul 2000 21:06:38 +0000
Subject: Re: Arrays
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-1651@lists.php.net to get a copy of this message
> > > What's the easiest way to loop through an array? I am using PHP3 - I > know > > > that PHP4 has a "foreach" structure, but sadly this is not there in > version > > > 3. I know it's probably something to do with a "while" loop - but how > > > exactly is it done? I have an array of 5 variables, and some of the > > > variables may be empty. > > > > while(list($key,$value)=each($array)) { > > echo "$key: $value<br>\n"; > > } > > > > -Rasmus > > Thanks... I'm a bit of a newbie, so I'm not sure what the $key variable > does... is it the index for the array? Yup. If your array looked like this: $a[5] = "Horse"; $a["blah"] = 47; The output would be: 5: Horse blah: 47 -Rasmus

« previous php.db (#1651) next »