|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-10-02 21:31 UTC] fa@php.net
[2009-10-03 00:37 UTC] rasmus@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 21:00:01 2025 UTC |
Description: ------------ I don't expect the $total in the second foreach to still be a reference to the last item from the previous foreach. Reproduce code: --------------- <?php $totals = array(array('class' => 'Foo', 'value' => '1'), array('class' => 'Test', 'value' => '2'), array('class' => 'Bar', 'value' => '3')); foreach ($totals as &$total) { switch ($total['class']) { case 'Test': $total['value'] *= 2; break; default: break; } } foreach ($totals as $total) { echo $total['class'] . ' : ' . $total['value'] . "\n"; } ?> Expected result: ---------------- Foo : 1 Test : 4 Bar : 3 Actual result: -------------- Foo : 1 Test : 4 Test : 4