From: owidjaya at gmail dot com Operating system: PHP version: 5.2.4 PHP Bug Type: *General Issues Bug description: key function in foreach array does not start from the beginning of array
Description: ------------ key function within foreach array does not start from the very beginning of the array instead it starts from the 2nd element Reproduce code: --------------- $courses= array( 1=>"test", 2=>"test2", 3=>"test3" ); echo key($courses)."\n"; foreach($courses as $key=>$course){ echo $key ." ". $course."\n"; } reset($courses); echo "\n"; echo key($courses)."\n"; foreach($courses as $course){ echo key($courses) ." ". $course."\n"; next($courses); } Expected result: ---------------- 1 1 test 2 test2 3 test3 1 1 test 2 test2 3 test3 Actual result: -------------- 1 1 test 2 test2 3 test3 1 2 test 3 test2 test3 -- Edit bug report at http://bugs.php.net/?id=42690&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42690&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42690&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42690&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=42690&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=42690&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=42690&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=42690&r=needscript Try newer version: http://bugs.php.net/fix.php?id=42690&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=42690&r=support Expected behavior: http://bugs.php.net/fix.php?id=42690&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=42690&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=42690&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=42690&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42690&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=42690&r=dst IIS Stability: http://bugs.php.net/fix.php?id=42690&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=42690&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=42690&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=42690&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=42690&r=mysqlcfg