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>";
?>

Kør eksempel

Definition and usage

The pos() function returns the value of the current element in the array.

This function is current() Function alias.

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() - Return the value of the current element in the array
  • end() - Move the internal pointer to the last element in the array and output
  • next() - Move the internal pointer to the next element in the array and output
  • prev() - Move the internal pointer to the previous element in the array and output
  • reset() - Move the internal pointer to the first element in the array and output
  • each() - Return the key name and value of the current element, and move the internal pointer forward

Syntax

pos(array)
Parameter Description
array Required. Specifies the array to be used.

Technical details

Return value: Return the value of the current element in the array. If the current element is empty or the current element has no value, return FALSE.
PHP version: 4+

Flere eksempler

Eksempel 1

Demonstrer alle relevante metoder:

<?php
$people = array("Bill", "Steve", "Mark", "David");
echo current($people) . "<br>"; // Den aktuelle element er Bill
echo next($people) . "<br>"; // Bills næste element er Steve
echo current($people) . "<br>"; // Den nuværende element er Steve
echo prev($people) . "<br>"; // Steves tidligere element er Bill
echo end($people) . "<br>"; // Den sidste element er David
echo prev($people) . "<br>"; // Davids tidligere element er Mark
echo current($people) . "<br>"; // Den aktuelle element er Mark
echo reset($people) . "<br>"; // Flytter den interne pegefinger til det første element i arrayet, dvs. Bill
echo next($people) . "<br>"; // Bills næste element er Steve
print_r (each($people)); // Returnerer den aktuelle elements nøgle og værdi (nu er det Steve), og flytter den interne pegefinger fremad
?>

Kør eksempel