note 8856 modified in foreach by ronabop

From: Date: Wed, 04 Oct 2000 14:28:12 +0000
Subject: note 8856 modified in foreach by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-6008@lists.php.net to get a copy of this message
When the array is an associative array, each element has two indexes: an integer and a string. foreach() will generate *two* values for each element. (You get an associative array when you use mysql_fetch_array() to retrieve a record from a query result.) The problem with foreach returning 2 values froman associative array returned by mysql_fetch_array() can be solved by using mysql_fetch_row() which returns an array indexed only by integers or mysql_fetch_assoc() which returns an array indexed only by strings. http://www.php.net/manual/control-structures.foreach.php

« previous php.notes (#6008) next »