each() function in PHP

PHPz
Release: 2023-08-20 10:10:02
forward
1189 people have browsed it

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)
Copy after login

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));
?>
Copy after login

Output

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

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

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template