Home >>PHP Array Functions >PHP current() Function
PHP current() function is used to return the value of the element that is currently being pointed by the internal pointer in the given array. It does not made any changes in the internal pointer after returning the value. It accepts a single parameter $array which is the given input array. It returns the value of the current pointing element in the array.
Syntax:
current($array);
Parameter | Description |
---|---|
array | This is a required parameter. This parameter defines the array to use. |
Here is an example of current() function in PHP:
<html> <body> <?php $x = array("a","b","c","d","e","f","g","h"); echo current($x)."<br>"; ?> </body> </html>
a
Example 2:
<html> <body> <?php $x = array("a","b","c","d","e","f","g","h"); echo current($x)."<br>"; // The current element is a echo next($x) . "<br>"; // The next element of a is b echo current($x) . "<br>"; // Now the current element is b echo end($x) . "<br>"; // The last element is h echo current($x) . "<br>"; // Now the current element is h ?> </body> </html>
a b b h h