PHP 8.5.0 Alpha 1 available for testing

Voting

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

The Note You're Voting On

amby2 at izh dot com
19 years ago
I've found a compact way to cycle through an associative array using for statement (not while, as it has been done in the most of examples below):

<?php

for (reset($array); list($key) = each($array);) {
echo
$key;
echo
$array[$key];
}

?>

or

<?php

for (reset($array); list($key, $value) = each($array);) {
echo
$key;
echo
$value;
echo
$array[$key];
}

?>

You hardly forget to add reset($array) code line using such construction.

<< Back to user notes page

To Top