current
mixed current(array array)
Returns the current element in the array without moving the internal array pointer.
Returns:
Value of the current element in the array; FALSE when no more elements exist
Description:
Returns the element value currently pointed to by the internal array pointer. This can be useful with next() and prev() in order to traverse an array; however, this is dangerous. The reason is that current() returns the value of the current element; if this evaluates to FALSE, there is no way to tell whether you've actually hit the end of the array being traversed or the current element simply has a value of FALSE.
This function does not move the internal array pointer.
Version:
PHP 3, PHP 4
See also:
end()
key()
next()
prev()
reset()
Example:
Get the value of the current element of an array
$my_array = array("a","b","c","d","e");
echo "Current: ", current($my_array), "\n";
for ($i = count($my_array); $i >= 0; $i--) {
echo "Next: ", next($my_array), "\n";
}
reset($my_array);
echo "Current: ", current($my_array);
Output:
Current: a
Next: b
Next: c
Next: d
Next: e
Current: e
|