PHP 8.4.24 Released!

Voting

: max(zero, four)?
(Example: nine)

The Note You're Voting On

sjoerd-php at linuxonly dot nl
20 years ago
Use foreach instead of while, list and each. Foreach is:
- easier to read
- faster
- not influenced by the array pointer, so it does not need reset().

It works like this:
<?php
$arr = array('foo', 'bar');
foreach ($arr as $value) {
    echo "The value is $value.";
}

$arr = array('key' => 'value', 'foo' => 'bar');
foreach ($arr as $key => $value) {
    echo "Key: $key, value: $value";
}
?>

<< Back to user notes page

To Top