PHP - Function current()


Advertisements


Syntax

current ( $array );

Definition and Usage

Every array has an internal pointer to its "current" element, which is initialized to the first element inserted into the array.

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array

Return Value

It returns the current element in an array.

Example

Try out following example −

<?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 />";
?> 

This will produce the following result −

foot
bike
bike
foot
plane
plane 

php_function_reference.htm

Advertisements