#21836 [NEW]: foreach runs 2 times thru array

From: Date: Thu, 23 Jan 2003 09:53:40 +0000
Subject: #21836 [NEW]: foreach runs 2 times thru array
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-31047@lists.php.net to get a copy of this message
From: double-dd@gmx.net Operating system: Windows 2000 PHP version: 4.3.0 PHP Bug Type: Arrays related Bug description: foreach runs 2 times thru array I have a result from dbx_query that should be written in a table. The outer foreach() runs thru the rows (correctly), the inner foreach() thru the columns of every row. (Just like the example for foreach() in the docu.) My output are 4 cols(!), the 1st, the 2nd, and again the 1st and the 2nd. But I recieved only 2 columns from the database. When I use a for() instead of foreach() (as commended out), it performs correctly. $result = dbx_query($dbhandle, "SELECT emp_fname, emp_lname FROM employee;"); foreach($result->data as $row) { echo "<tr>\n"; foreach($row as $field) { echo "<td>" . $field . "</td>\n"; } //for($i = 0; $i < $result->cols; $i++) { // echo "<td>" . $row[$i] . "</td>\n"; } echo "</tr>\n"; } -- Edit bug report at http://bugs.php.net/?id=21836&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=21836&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=21836&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=21836&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=21836&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=21836&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=21836&r=support Expected behavior: http://bugs.php.net/fix.php?id=21836&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=21836&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=21836&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=21836&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21836&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=21836&r=dst IIS Stability: http://bugs.php.net/fix.php?id=21836&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=21836&r=gnused

« previous php.bugs (#31047) next »