PHP

PHP Menu

PHP

current() Function - Definition, Syntax, Parameters, Examples

Definition

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

The current() function is commonly used along with the following functions:

  • prev() – Moves the internal pointer of an array to the previous element, and returns its value.
  • next() – Moves the internal pointer of an array to the next element, and returns its value.
  • end() – Moves the internal pointer of an array to its last element, and returns its value.
  • reset() – Set the internal pointer of an array to its first element, and returns its value.
  • key() – Returns the key of the current element in an array.

Syntax

current(array)

Parameters

Parameter Description
array Required. Specifies the array to use.

Example

<?php
// Example 1 $cities = array("New York", "Salt Lake", "Tokyo"); echo current($cities) . "<br>";
// Example 2 $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); echo current($ages) . "<br>";
// Examples in conjuction with other related functions echo current($ages) . "<br>"; echo next($ages) . "<br>"; echo current($ages) . "<br>"; echo prev($ages) . "<br>"; echo end($ages) . "<br>"; echo prev($ages) . "<br>"; echo current($ages) . "<br>"; echo reset($ages) . "<br>"; echo next($ages) . "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods