- reset: documentation ( source)
- key: documentation ( source)
- next: documentation ( source)
- current: documentation ( source)
<?php
function print_while_each($list) {
while (list($key, $val) = each($list)) {
echo $key, $val;
if ($val == '2') {
$list[] = 4;
}
}
}
function print_foreach($list) {
foreach ($list as $key => $val) {
echo $key, $val;
if ($val == '2') {
$list[] = 4;
}
}
}
function print_while_next($list) {
$val = reset($list);
while (!empty($val)) {
$key = key($list);
$val = current($list);
echo $key, $val;
if ($val == '2') {
$list[] = 4;
}
$val = next($list);
}
}
$list = array('1', '2', '3');
print_while_each($list);
echo '<br>', PHP_EOL;
print_foreach($list);
echo '<br>', PHP_EOL;
print_while_next($list);
echo '<br>', PHP_EOL;