pos() is a built-in function in PHP that returns the value of the element in the array currently pointed to by the internal pointer. After returning a value, the pos() function does not increment or decrement the internal pointer. In PHP, all arrays have an internal pointer. This internal pointer points to an element in the array, which is called the current element of the array. Normally, the current element is the first inserted element in the array.
Syntax:
pos($array)
Parameters: The pos() function accepts a single parameter $array. It is the array in which we want to find the current element.
Return value: It returns the value of the element in the array currently pointed by the internal pointer. If the array is empty, the pos() function returns FALSE.
PHP Code Example 1:
<?php $arr = array("PHP", "Java", "Python", "Go"); echo pos($arr)."\n"; echo next($arr)."\n"; echo pos($arr)."\n"; echo prev($arr)."\n"; echo end($arr)."\n"; echo pos($arr)."\n";
Output:
PHP Java Java PHP Go Go
Code Example 2:
<?php $arr = array("P", "6", "M", "F"); echo pos($arr)."\n"; echo next($arr)."\n"; echo pos($arr)."\n"; echo prev($arr)."\n"; echo end($arr)."\n"; echo pos($arr)."\n";
Output:
P 6 6 P F F
Recommended related video tutorials: "PHP Tutorial"
This article is about the use of the php pos() function. I hope it will be helpful to friends in need!
The above is the detailed content of Detailed explanation of the use of php pos() function. For more information, please follow other related articles on the PHP Chinese website!