ID:          42690
 Updated by:  [EMAIL PROTECTED]
 Reported By: owidjaya at gmail dot com
-Status:      Open
+Status:      Bogus
-Bug Type:    *General Issues
+Bug Type:    Arrays related
 PHP Version: 5.2.4
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Using key/next/prev/etc. in foreach() is unsupported. (foreach does an
internal reset() in it too!) 

And using key() in foreach is pretty useless since it provides that
with syntax foreach($arr as $key => $val)


Previous Comments:
------------------------------------------------------------------------

[2007-09-17 23:13:54] owidjaya at gmail dot com

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 this bug report at http://bugs.php.net/?id=42690&edit=1

Reply via email to