|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-08-26 10:06 UTC] laruence@php.net
[2016-08-26 12:39 UTC] cmb@php.net
-Status: Open
+Status: Feedback
[2016-09-04 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 19:00:02 2025 UTC |
Description: ------------ same array variable($reqs) when it was assign value with &, then use foreach to loop it again, the last loop variable value was assigned failed. please,see the simple test script below. Test script: --------------- function foo() { $reqs = array('11', '22', array('id' => 123, 'name' => 'ffff')); foreach ($reqs as &$req) { if (is_array($req)) { $req['name'] = 'dd'; //alter value } } echo '<pre>'; print_r($reqs); //values changed, ok echo '</pre>'; foreach ($reqs as $req) { echo '<pre>'; print_r($req); //the last value is '22', that is wrong. echo '</pre>'; } } output: 11 22 22 //it should be output this: array('id' => 123, 'name' => 'ffff') Expected result: ---------------- expect output result: 11 22 Array ( [id] => 123 [name] => ffff ) Actual result: -------------- 11 22 22