Web | This Site

Learning PHP
Advanced PHP
PHP Function Reference
PHP Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# PHP Function current()

## 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

Parameter | Description
--- | ---
array | Required. 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

Advertisement

Online Image Processing

Indian Baby Names