PHP current() Function

PHP current Function


Definition:

An array in PHP has a current pointer which points to the first element by default, current() function is used to get the current elements of an array. It accepts an array and returns its current element.

Syntax:

    current(array);

Note:

  • In an array which contains keys and values, it returns only value not a key.
  • current() returns only the current element, it does not move the pointer to next element. 

Parameter:

Parameter Description
array Required. Specifies the array to use

Example1 : we can see below Output the value of the current element in an array

Output : web

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.

Example2 :  Below example we can see the uses of current() functions

Output :

web
Designing
Designing
web
House
Designing
Designing
web
Designing