Home  >  Article  >  Backend Development  >  each() function in PHP

each() function in PHP

PHPz
PHPzforward
2023-08-20 10:09:081179browse

each() function in PHP

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

Note − As of PHP 7.2.0, this function is deprecated and should be avoided.

Syntax

each(arr)

Parameters

  • arr - The specified array

Return value

each() function returns the key and value of the current element. This will be returned as an array with four elements, including:

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

  • Two elements (0 and key) are used for element keys.

Example

The following is an example -

Demonstration

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

Output

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

The above is the detailed content of each() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete