each() function in PHP


The each() function returns the current key and value pair from an array.

Note − This function has been deprecated as of PHP 7.2.0 and should be avoided.

Syntax

each(arr)

Parameters

  • arr − The specified array

Return

The each() function returns the current element key and value. This is returned in an array with four elements −

  • Two elements (1 and value) for the element value, and

  • Two elements (0 and key) for the element key.

Example

The following is an example −

 Live Demo

<?php
$prod = array("Electronics", "Footwear", "Toys");
print_r (each($prod));
?>

Output

Array (
   [1] => Electronics
   [value] => Electronics
   [0] => 0
   [key] => 0
)

Updated on: 24-Jun-2020

156 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements