xref: /PHP-8.2/tests/lang/foreachLoop.005.phpt (revision 3f72c77c)
1--TEST--
2Foreach loop tests - modifying the array during the loop: special case. Behaviour is good since php 5.2.2.
3--FILE--
4<?php
5$a = array("original.0","original.1","original.2");
6foreach ($a as $k=>&$v){
7  $a[$k] = "changed.$k";
8  echo "After changing \$a directly, \$v@$k is: $v\n";
9}
10//--- Expected output:
11//After changing $a directly, $v@0 is: changed.0
12//After changing $a directly, $v@1 is: changed.1
13//After changing $a directly, $v@2 is: changed.2
14//--- Actual output from php.net before 5.2.2:
15//After changing $a directly, $v@0 is: changed.0
16//After changing $a directly, $v@1 is: original.1
17//After changing $a directly, $v@2 is: original.2
18
19?>
20--EXPECT--
21After changing $a directly, $v@0 is: changed.0
22After changing $a directly, $v@1 is: changed.1
23After changing $a directly, $v@2 is: changed.2
24