note 30183 added to ref.array

From: Date: Sun, 09 Mar 2003 22:34:09 +0000
Subject: note 30183 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-45046@lists.php.net to get a copy of this message
After doing a lot of research i discovered that multidimensional arrays did not work as some people explained. Suppose the table "Projecten" contains: project_id,project_omschrijving 1,first 2,second And using the next code $proj_result = pg_query("SELECT * FROM \"Projecten\"") or die (pg_last_error()); if ($myrow = pg_fetch_array($proj_result)) { do { $proj[][0]=$myrow["project_id"]; $proj[][1]=$myrow["project_omschrijving"]; } while ($myrow = pg_fetch_array($proj_result)); } Would create an array: $proj[0][0]=1 $proj[0][1]=first $proj[1][0]=2 $proj[1][1]=second I would then expect foreach( $proj as $s) to give me: $s as an array containing(1,first) and the next foreach loop would give me an array $s=(2,second). But this is not working here. It returns (first) So be carefull when using foreach and the other walkers of arrays when using mutliple dimension arrays. Be prepared to walk value by value and act accordingly. This took me sometime to figure out. -- http://www.php.net/manual/en/ref.array.php http://master.php.net/manage/user-notes.php?action=edit+30183 http://master.php.net/manage/user-notes.php?action=delete+30183 http://master.php.net/manage/user-notes.php?action=reject+30183

« previous php.notes (#45046) next »