ID:               44006
 Updated by:       [EMAIL PROTECTED]
 Reported By:      crashrox at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: SunOS 5.10 Generic_127
 PHP Version:      5.2.5
 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

Don't use foreach + next/current/...


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

[2008-01-31 20:07:16] crashrox at gmail dot com

Description:
------------
Next function is not returning a value when it should be. Tried code
sample below on a linux and windows distro both running PHP 5.2.1 and
received desired results. When tested on SunOS 5.10 and PHP 5.2.4 the
undesired results appeared.

Reproduce code:
---------------
$array = array(
                        'key1' => array(
                                'sub1_key1',
                                'sub1_key2',
                                'sub1_key3',
                                'sub1_key4',
                        ),
                        
                        'key2' => array(
                                'sub2_key1',
                                'sub2_key2',
                                'sub2_key3',
                                'sub2_key4',
                        )
                );
                
                foreach($array as $key => $sub_array) {
                        
                        foreach($sub_array as $sub_val) {
                                echo $sub_val;
                                
                                if(next($sub_array))
                                        echo ', ';
                        }
                        
                        $next = next($array);
                        if(is_array($next)) {
                                echo '||||';
                        }
                
                        print_r($next);
                
                }

Expected result:
----------------
sub1_key1, sub1_key2, sub1_key3, sub1_key4||||Array
(
    [0] => sub2_key1
    [1] => sub2_key2
    [2] => sub2_key3
    [3] => sub2_key4
)
sub2_key1, sub2_key2, sub2_key3, sub2_key4

Actual result:
--------------
sub1_key1, sub1_key2, sub1_key3, sub1_key4sub2_key1, sub2_key2,
sub2_key3, sub2_key4


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44006&edit=1

Reply via email to