PHP Loops

foreach

$a = ['foo' => 1, 'bar' => 2];
# => 12
foreach ($a as $k) {
    echo $k;
}

See: Array iteration

continue

# => 1235
for ($i = 1; $i <= 5; $i++) {
    if ($i === 4) {
        continue;
    }
    echo $i;
}

break

# => 123
for ($i = 1; $i <= 5; $i++) {
    if ($i === 4) {
        break;
    }
    echo $i;
}

for i

# => 12345
for ($i = 1; $i <= 5; $i++) {
    echo $i;
}

do while

$i = 1;
# => 12345
do {
    echo $i++;
} while ($i <= 5);

while

$i = 1;
# => 12345
while ($i <= 5) {
    echo $i++;
}
Comments