summaryrefslogtreecommitdiff
path: root/tests/lang/foreachLoop.001.phpt
blob: a7ec701fd1406508ee90be4997e93fdea1bec94c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--TEST--
Foreach loop tests - basic loop with just value and key => value.
--FILE--
<?php

$a = array("a","b","c");

foreach ($a as $v) {
	var_dump($v);
}
foreach ($a as $k => $v) {
	var_dump($k, $v);
}
//check key and value after the loop.
var_dump($k, $v);

echo "\n";
//Dynamic array
foreach (array("d","e","f") as $v) {
	var_dump($v);
}
foreach (array("d","e","f") as $k => $v) {
	var_dump($k, $v);
}
//check key and value after the loop.
var_dump($k, $v);

echo "\n";
//Ensure counter is advanced during loop
$a=array("a","b","c");
foreach ($a as $v);
var_dump(current($a));
$a=array("a","b","c");
foreach ($a as &$v);
var_dump(current($a));

?>
--EXPECT--
string(1) "a"
string(1) "b"
string(1) "c"
int(0)
string(1) "a"
int(1)
string(1) "b"
int(2)
string(1) "c"
int(2)
string(1) "c"

string(1) "d"
string(1) "e"
string(1) "f"
int(0)
string(1) "d"
int(1)
string(1) "e"
int(2)
string(1) "f"
int(2)
string(1) "f"

string(1) "a"
string(1) "a"