I'm a bit confused about array pointers in PHP. The below code worked fine:
$ages = [1, 3, 5];
while($age = current($ages)) {
echo $age . ", ";
next($ages);
}
But I've no idea why the below code didn't print any thing out:
$ages = [];
for($i = 0; $i < 10; $i++) {
$ages[] = $i;
}
while($age = current($ages)) {
echo $age . ", ";
next($ages);
}
I also tried to print with for loop, but in below code only the for loop printed, the while loop still didn't print.
$ages = [];
for($i = 0; $i < 10; $i++) {
$ages[] = $i;
}
for($i = 0; $i < 10; $i++) {
echo $ages[$i] . ", ";
}
while($age = current($ages)) {
echo $age . ", ";
next($ages);
}
I'm really not sure why it behaved like this, anyone could help me out?
foreach.