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 en exempel

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+

Mer exempel

Exempel 1

Demonstrera alla relaterade metoder:

<?php
$people = array("Bill", "Steve", "Mark", "David");
echo current($people) . "<br>"; // Det aktuella elementet är Bill
echo next($people) . "<br>"; // Bills nästa element är Steve
echo current($people) . "<br>"; // Den aktuella elementet är Steve
echo prev($people) . "<br>"; // Steves föregående element är Bill
echo end($people) . "<br>"; // Den sista elementet är David
echo prev($people) . "<br>"; // Davids föregående element är Mark
echo current($people) . "<br>"; // Den aktuella elementet är Mark
echo reset($people) . "<br>"; // Flyttar den inre pekaren till den första elementet i arrayen, dvs. Bill
echo next($people) . "<br>"; // Bills nästa element är Steve
print_r (each($people)); // Returnerar den aktuella elementets nyckelnamn och nyckelvärde (för närvarande är det Steve) och flyttar den inre pekaren framåt
?>

Kör en exempel