File:
[ELWIX - Embedded LightWeight unIX -] /
embedaddon /
php /
tests /
lang /
foreachLoop.001.phpt
Revision
1.1.1.1 (vendor branch):
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Feb 21 23:48:06 2012 UTC (12 years, 5 months ago) by
misho
Branches:
php,
MAIN
CVS tags:
v5_4_3elwix,
v5_4_29p0,
v5_4_29,
v5_4_20p0,
v5_4_20,
v5_4_17p0,
v5_4_17,
v5_3_10,
HEAD
php
--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"
bool(false)
bool(false)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>