Home >>PHP Array Functions >PHP pos() Function

PHP pos() Function

PHP pos() Function

PHP pos() function is used to get the value of the element in any given input array which the internal pointer is currently pointing to. It does not increment or decrement the internal pointer after returning the value. It accepts only a single parameter $array that is the given input array.

Syntax:

pos($array);

Parameter Values

Parameter Description
array This is a required parameter. It defines the array to use.

Here is an example of pos() function in PHP:

<html>
<body>
<?php
$x = array("A","B","C","D","E","F","G");
echo pos($x);
?>
</body>
</html>
Output:
A

Example 2:

<html>
<body>
<?php 
$x = array("A","B","C","D","E","F","G");
echo pos($x)."<br>"; 
echo next($x)."<br>"; 
echo pos($x)."<br>"; 
echo prev($x)."<br>";
echo pos($x)."<br>"; 
echo end($x)."<br>"; 
echo pos($x)."<br>"; 
?> 
</body>
</html>
Output:
A
B
B
A
A
G
G

No Sidebar ads