Copyright © tutorialspoint.com

PHP Function current()

previous
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.

The current() function simply returns the value of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list, current() returns FALSE.

Paramters

ParameterDescription
arrayRequired. Specifies an array

Return Value

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 following result:

foot
bike
bike
foot
plane
plane 
previous

Copyright © tutorialspoint.com