Re: Equivelant to mysql_fetch_row for normal array

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

 



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 />";
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux