current :
Return the current element in an array.
Syntax :
current ( array &$array )
Every array has an internal pointer to its "current" element, which is initialized to the first element inserted into the array.
The current() function simply returns the value of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, current() returns FALSE.
Example :
<?php
$Alphabet = array('A', 'B', 'C', 'D');
$mode = current($Alphabet); //
$mode = 'A';
$mode = next($Alphabet); //
$mode = 'B';
$mode = current($Alphabet); //
$mode = 'B';
$mode = prev($Alphabet); //
$mode = 'A';
$mode = end($Alphabet); //
$mode = 'D';
$mode = current($Alphabet); //
$mode = 'D';
$arr = array();
var_dump(current($arr));
// bool(false)
$arr = array(array());
var_dump(current($arr)); //
array(0) { }
?>
Related Other
methods:
end() - moves the internal pointer to, and outputs, the last
element in the array
next() - moves the internal pointer to, and outputs, the next
element in the array
prev() - moves the internal pointer to, and outputs, the previous
element in the array
reset() - moves the internal pointer to the first element of the
array
each() - returns the current element key and value, and moves the
internal pointer forward
Comments
Post a Comment