|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-18 18:19 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 21:00:01 2025 UTC |
Description: ------------ Apparently, the foreach loop such as "foreach ($array as $value)" puts some kind of index-value array into $value. This differs from what the documentation says and does not seem to appear in changelog or make any sense. The code below produces different results on 4.3.9 and 4.3.10 Reproduce code: --------------- <?php $a = array( 'ab' => array( 'a' => 1, 'b' => 2 ), 'cd' => array( 'c' => 3, 'd' => 4 ) ); foreach ($a as $key => $array) { echo '<br />key ' . $key . ', array: '; var_dump($array); foreach ($array as $datafield) { echo '<br />key ' . $key . ', subarray element: '; var_dump($datafield); } } ?> Expected result: ---------------- PHP 4.3.9: key ab, array: Array ( [a] => 1 [b] => 2 ) key ab, subarray element: 1 key ab, subarray element: 2 key cd, array: Array ( [c] => 3 [d] => 4 ) key cd, subarray element: 3 key cd, subarray element: 4 Actual result: -------------- PHP 4.3.10: key ab, array: Array ( [a] => 1 [b] => 2 ) key ab, subarray element: Array ( [0] => 1 [1] => a ) key ab, subarray element: Array ( [0] => 2 [1] => b ) key cd, array: Array ( [c] => 3 [d] => 4 ) key cd, subarray element: Array ( [0] => 3 [1] => c ) key cd, subarray element: Array ( [0] => 4 [1] => d )