current() function in PHP


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)."
"; echo next($a)."
"; echo current($a)."
"; ?>

Output

The following is the output −

one
two
two

Updated on: 23-Dec-2019

107 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements