each in PHP

Syntax of each in PHP

array each(array &array)

Creates an array containing the keys and values of the element currently pointed at by the array’s internal pointer. The array contains four elements: elements with the keys 0 and key from the element containing the key of the element, and elements with the keys 1 and value containing the value of the element.

If the internal pointer of the array points beyond the end of the array, each() returns false.

Example of each

<?php
$foo = array("bob", "fred", "jussi", "jouni", "egon", "marliese");
$bar = each($foo);
print_r($bar);
?>
Array
(
    [1] => bob
    [value] => bob
    [0] => 0
    [key] => 0
)

Leave a Comment