xref: /PHP-8.1/tests/lang/foreachLoop.004.phpt (revision f8d79582)
1--TEST--
2Foreach loop tests - using an array element as the $value
3--FILE--
4<?php
5
6$a=array("a", "b", "c");
7$v=array();
8foreach($a as $v[0]) {
9    var_dump($v);
10}
11var_dump($a);
12var_dump($v);
13
14echo "\n";
15$a=array("a", "b", "c");
16$v=array();
17foreach($a as $k=>$v[0]) {
18    var_dump($k, $v);
19}
20var_dump($a);
21var_dump($k, $v);
22?>
23--EXPECT--
24array(1) {
25  [0]=>
26  string(1) "a"
27}
28array(1) {
29  [0]=>
30  string(1) "b"
31}
32array(1) {
33  [0]=>
34  string(1) "c"
35}
36array(3) {
37  [0]=>
38  string(1) "a"
39  [1]=>
40  string(1) "b"
41  [2]=>
42  string(1) "c"
43}
44array(1) {
45  [0]=>
46  string(1) "c"
47}
48
49int(0)
50array(1) {
51  [0]=>
52  string(1) "a"
53}
54int(1)
55array(1) {
56  [0]=>
57  string(1) "b"
58}
59int(2)
60array(1) {
61  [0]=>
62  string(1) "c"
63}
64array(3) {
65  [0]=>
66  string(1) "a"
67  [1]=>
68  string(1) "b"
69  [2]=>
70  string(1) "c"
71}
72int(2)
73array(1) {
74  [0]=>
75  string(1) "c"
76}
77