Voting

: four minus three?
(Example: nine)

The Note You're Voting On

sjoerd-php at linuxonly dot nl
19 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