␡
- Accessing All Elements of Numeric Arrays
- Accessing All Elements of Associative Arrays
- Accessing All Array Elements in Nested Arrays
- Turning an Array into Variables
- Converting Strings to Arrays
- Converting Arrays to Strings
- Sorting Arrays Alphabetically
- Sorting Associative Arrays Alphabetically
- Sorting Nested Arrays
- Sorting Nested Associative Arrays
- Sorting IP Addresses (as a Human Would)
- Sorting Anything
- Sorting with Foreign Languages
- Applying an Effect to All Array Elements
- Filtering Arrays
- Getting Random Elements Out of Arrays
- Making Objects Behave Like Arrays
This chapter is from the book
Turning an Array into Variables
while (list($key, $value) = each($a))
<?php $a = array('one' => 'I', 'two' => 'II', 'three' => 'III', 'four' => 'IV'); while (list($key, $value) = each($a)) { echo htmlspecialchars("$key: $value") . '<br />'; } ?>
Looping through an Array with list() and each() (each-list.php)
Whenever each() is used, the use of list() is a good idea. Within list(), you provide variable names for all values with numeric indices in the array that is returned by each(). This makes while/each() loops even easier to use, as the code shows. Within the parentheses, the variable names are provided.
while (list(, $value) = each($a)) { echo htmlspecialchars("$value") . '<br />'; }