each

NAME

each - retrieve the next key/value pair from a hash


SYNOPSIS

each ASSOC_ARRAY


DESCRIPTION

Returns a 2-element array consisting of the key and value for the next value of an associative array, so that you can iterate over it. Entries are returned in an apparently random order. When the array is entirely read, a null array is returned (which when assigned produces a FALSE (0) value). The next call to each() after that will start iterating again. The iterator can be reset only by reading all the elements from the array. You should not add elements to an array while you're iterating over it. There is a single iterator for each associative array, shared by all each() , keys() and values() function calls in the program. The following prints out your environment like the printenv(1) program, only in a different order:

while (($key,$value) = each %ENV) { print "$key=$value\n"; }

See also keys() and values() .