English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP current() function usage and example

PHP Array Function Manual

The current() function returns the current element in the array

Syntax

current($array);

Definition and usage

Each array has an internal pointer pointing to its 'current' element, which is initialized to the first element inserted into the array.

Parameter

Serial numberParameters and descriptions
1

array(Required)

It specifies an array

Return value

It returns the current element in the array.

Online example

The current() function returns the current element of the array, as well as the current element returned after using functions such as next(), prev(), end(), etc.

<?php
   $transport = array('foot', 'bike', 'car', 'plane');
   $mode = current($transport); 
   print "$mode	<br />";
   
   $mode = next($transport);  
   print "$mode	<br />";
   
   $mode = current($transport);
   print "$mode	<br />";
   
   $mode = prev($transport);  
   print "$mode	<br />";
   
   $mode = end($transport);
   print "$mode	<br />";
   
   $mode = current($transport); 
   print "$mode	<br />";
?>
Test and see‹/›

Output result:

foot
bike
bike
foot
plane
plane

  PHP Array Function Manual