value current(array arrayname)
The current function returns the value of the current element pointed to by PHP's
internal pointer. Each array maintains a pointer to one of the elements of an array. By
default it points to the first element added to the array until it is moved by a function such
as next or reset.
<?
//create test data
$colors = array("red", "green", "blue");
//loop through array using current
for(reset($colors); $value = current($colors); next($colors))
{
print("$value
\n");
}
?>
array each(array arrayname)
The each function returns a four-element array that represents the next value from an
array. The four elements of the returned array ( 0 , 1 , key, and value) refer to the key and
value of the current element. You may refer to the key with 0 or key, and to get the value
use 1 or value. You may traverse an entire array by repeatedly using list and each, as
in the example below.
<?
//create test data
$colors = array("red", "green", "blue");
//loop through array using each
//output will be like "0 = red"
while(list($key, $value) = each($colors))
{
print("$key = $value
\n");
}
?>
end(array arrayname)
The end function moves PHP's internal array pointer to the array's last element. The reset
function moves the internal pointer to the first element.
<?
$colors = array("red", "green", "blue");
end($colors);