PHP array each() Function
Last Updated : 17 Mar 2025
The each( ) function is an inbuilt function of PHP. It is used to fetch the key and value of the current element and moves the internal pointer forward. This function was introduced in PHP 4.0.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array | Specifies the array to use. | compulsory |
Returns
The each() function returns the current key and value pair from array_name.
Example 1
Output:
Array
(
[1] => OS
[value] => OS
[0] => 0
[key] => 0
)
Example 2
Output:
Array
(
[1] =>sachin
[value] =>sachin
[0] => 0
[key] => 0
)
Example 3
Output:
Array
(
[1] => dell
[value] =>dell
[0] => 0
[key] => 0
)
Example 4
Output:
Array
(
[1] =>bengaluru
[value] =>bengaluru
[0] =>karnataka
[key] =>karnataka
)
Next TopicPhp-array-end-function