current() function in PHP

PHPProgrammingServer Side Programming

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

Syntax

current(arr)

Parameters

  • arr − The specified array. Required.

Return

The current() function returns the value of the current element in an array.

Example

The following is an example −

 Live Demo

<?php
$arr = array("one", "two");
echo current($arr);
?>

Output

The following is the output −

one

Example

Let us see another example −

 Live Demo

<?php
$a = array('one', 'two', 'three', 'four', 'five', 'six' );
echo current($a)."\n";
echo next($a)."\n";
echo current($a)."\n";
?>

Output

The following is the output −

one
two
two
raja
Published on 15-Oct-2018 09:22:45

Advertisements