PHP pos() function
Example
Output the value of the current element in the array:
<?php $people = array("Bill", "Steve", "Mark", "David"); echo pos($people) . "<br>"; ?>
Definition and Usage
The pos() function returns the value of the current element in the array.
This function is current() Function Aliases.
Each array has an internal pointer that points to its 'current' element, initially pointing to the first element inserted into the array.
Tip:This function does not move the internal pointer of the array.
Related Methods:
- current() - Returns the value of the current element in the array
- end() - Moves the internal pointer to the last element in the array and outputs
- next() - Moves the internal pointer to the next element in the array and outputs
- prev() - Moves the internal pointer to the previous element in the array and outputs
- reset() - Moves the internal pointer to the first element in the array and outputs
- each() - Returns the key name and key value of the current element and moves the internal pointer forward
Syntax
pos(array)
Parameter | Description |
---|---|
array | Required. Specifies the array to be used. |
Technical Details
Return value: | Returns the value of the current element in the array. If the current element is empty or does not have a value, FALSE is returned. |
PHP-Version: | 4+ |
Mehr Beispiele
Beispiel 1
Demonstrieren Sie alle verwandten Methoden:
<?php $people = array("Bill", "Steve", "Mark", "David"); echo current($people) . "<br>"; // Der aktuelle aktuelle Element ist Bill echo next($people) . "<br>"; // Der nächste Element von Bill ist Steve echo current($people) . "<br>"; // Der aktuelle aktuelle Element ist Steve echo prev($people) . "<br>"; // Der vorherige Element von Steve ist Bill echo end($people) . "<br>"; // Der letzte Element ist David echo prev($people) . "<br>"; // Der vorherige Element von David ist Mark echo current($people) . "<br>"; // Der aktuelle aktuelle Element ist Mark echo reset($people) . "<br>"; // Bewegt den internen Zeiger zum ersten Element des Arrays, d.h. Bill echo next($people) . "<br>"; // Der nächste Element von Bill ist Steve print_r (each($people)); // Gibt den aktuellen Schlüsselnamen und -wert zurück (derzeit ist es Steve) und bewegt den internen Zeiger nach vorne ?>