Re: Equivelant to mysql_fetch_row for normal array

From: Date: Fri, 23 Jun 2006 17:25:38 +0000
Subject: Re: Equivelant to mysql_fetch_row for normal array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-238558@lists.php.net to get a copy of this message
Dave M G wrote: > Nicolas, Jochem, Tul, > > I have been going mental, reading the online manual and trying different > things. I can not get this loop to work. > > Please understand that I have endeavored to read up on list(), each(), > foreach(), while(). key(), and everything else I can. I've even looked > at online tutorials and I have to PHP books here. I'm asking on list not > because I come here before searching for existing help, it's because I > don't understand the help that I've found. > > In fact, I've tried lifting code directly from a book I recently bought > on PHP, called "All In One: PHP, MySQL and Apache". > foreach($elements as $e){ > while(list($key, $value) = each($e)){ > echo "key = " . $key . "<br />"; > echo "value = " . $value . "<br />"; > } > } don't fix list()+each() with foreach() ... // things to do when your stuck: echo '<pre>'; var_dump($elements); print_r($elements); foreach($elements as $e) { var_dump($e); print_r($e); } echo '</pre>'; // example 1 foreach($elements as $e) { echo "value= ",$e,"<br />"; } // example 2 foreach($elements as $key => $value) { echo "value= ",$value,"<br />"; echo "key= ",$key,"<br />"; } // example 3 reset($elements); while(list(, $value) = each($elements)) { echo "value = " . $value . "<br />"; } // example 4 reset($elements); while(list($key, $value) = each($elements)) { echo "key = " . $key . "<br />"; echo "value = " . $value . "<br />"; }

« previous php.general (#238558) next »