PHP pos() function

PHP natsort() function
PHP next() function

In the article, you will learn how to get the value of the element where the internal pointer of an array is. The pos() function returns the value of the element of the array where the internal pointer is pointing to. It does not move the pointer in any direction.

This method is an alias of the current() method.

What is the syntax of the pos() function in PHP?

pos(array)
ParameterDetails
arrayThe array to get the value at current pointer position – Required
PHP next() function

Examples of pos() function

Example 1. Get the current value of the array.

<?php
$arr= array("Jawad", "Ahmad", "Sumerina");
echo pos($arr);
?>

Example 2. In this example, you will find all the methods related to the pos method category. These methods work with the internal pointer of the arrays.

<?php
$members= array("Jawad", "Ahmad", "Sumerina", "ACS");

// Current element: Jawad
echo current($people) . "<br>";

// Next element of Jawad: Ahmad
echo next($people) . "<br>"; 

// Now the current element: Ahmad
echo current($people) . "<br>"; 

// Previous element of Ahmad: Jawad
echo prev($people) . "<br>"; 

// Last element: ACS
echo end($people) . "<br>"; 

// Previous element of ACS: Sumerina
echo prev($people) . "<br>"; 

// Current element: Sumerina
echo current($people) . "<br>"; 

// Move the internal pointer to the first element of the array:Jawad
echo reset($people) . "<br>"; 

// Next element of Jawad: Ahmad
echo next($people) . "<br>"; 

// Get key and value of Ahmad (current element) then moves the internal pointer forward
print_r (each($members));
?>
PHP natsort() function
PHP next() function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top