update page now
PHP 8.1.34 Released!

Voting

: two plus four?
(Example: nine)

The Note You're Voting On

amby2 at izh dot com
20 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