Output the value of the current element in the array:
<?php$people = array("Peter", "Joe", "Glenn", "Cleveland");echo pos($people) . "<br>";?>The pos() function returns the value of the current element in the array.
This function is an alias of the current() function.
Each array has an internal pointer pointing to its "current" element, initially pointing to the first element inserted into the array.
Tip: This function does not move the array internal pointer.
Related methods:
current() - Returns the value of the current element in the array.
end() - Sets the internal pointer to the last element in the array and outputs it.
next() - Sets the internal pointer to the next element in the array and outputs it.
prev() - Sets the internal pointer to the previous element in the array and outputs it.
reset() - Sets the internal pointer to the first element in the array and outputs it.
each() - Returns the key name and value of the current element and moves the internal pointer forward.
pos( array )
parameter | describe |
---|---|
array | Required. Specifies the array to use. |
Return value: | Returns the value of the current element in the array, or FALSE if the current element is empty or has no value. |
---|---|
PHP version: | 4+ |
Demonstration of all relevant methods:
<?php$people = array("Peter", "Joe", "Glenn", "Cleveland");echo current($people) . "<br>"; // The current element is Peterecho next($people) . "<br>"; // The next element of Peter is Joeecho current($people) . "<br>"; // Now the current element is Joeecho prev($people) . "<br>"; // The previous element of Joe is Peterecho end($people) . "<br>"; // The last element is Clevelandecho prev($people) . "<br>"; // The previous element of Cleveland is Glennecho current($people) . "< br>"; // Now the current element is Glennecho reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peterecho next($people) . "<br >"; // The next element of Peter is Joeprint_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward?>