PHP | each() Function Last Updated : 25 May, 2018 Comments Improve Suggest changes Like Article Like Report The each() function is an inbuilt function in PHP which basically returns an array with four elements, two elements (1 and Value) for the element value, and two elements (0 and Key) for the element key and moves the cursor forward. Syntax: each(array) Parameters: Array: It specifies the array which is being taken as input and used for each() function. Return Values: It returns the current element key and value which are an array with four elements out of which two elements (1 and Value) for the element value, and two elements (0 and Key) for the element key.It returns FALSE if there are no array elements. PHP Version: 4+ Let's see PHP program: Program 1: PHP <?php // PHP program to demonstrate working of each() // for simple array. // input array contain some elements inside. $a = array("Ram", "Shita", "Geeta"); // each() function return in the array with four elements // Two elements (1 and Value) for the element value which // are Ram, and two elements (0 and Key) for the element // key which are not given here so output is zero. print_r (each($a)); // Next set is printed as cursor is moved print_r (each($a)); ?> Output: Array ( [1] => Ram [value] => Ram [0] => 0 [key] => 0 ) Array ( [1] => Shita [value] => Shita [0] => 1 [key] => 1 ) Program 2: PHP <?php // PHP program to demonstrate working of each() // for associative array. $a = array("101"=>"Ram", "105"=>"Geeta", "104"=>"Geek"); // each() function return in the array with four elements // Two elements (1 and Value) for the element value which // are Ram, and two elements (0 and Key) for the element // key which are Boy. print_r (each($a)); // Next set is printed as cursor is moved print_r (each($a)); ?> Output: Array ( [1] => Ram [value] => Ram [0] => 101 [key] => 101 ) Array ( [1] => Geeta [value] => Geeta [0] => 105 [key] => 105 ) Reference: http://php.net/manual/en/function.each.php Comment More infoAdvertise with us Next Article PHP | each() Function K Kanchan_Ray Follow Improve Article Tags : Misc Web Technologies PHP PHP-array Practice Tags : Misc Similar Reads PHP each() Function The each() function is an inbuilt function in PHP and is used to get the current element key-value pair of the given array to which the internal pointer is currently pointing. After returning the key and value of the current element the internal pointer is incremented by one in the array. Note: You 2 min read PHP extract() Function The extract() Function is an inbuilt function in PHP. The extract() function does array to variable conversion. That is it converts array keys into variable names and array values into variable value. In other words, we can say that the extract() function imports variables from an array to the symbo 3 min read PHP array() Function The array() function is an inbuilt function in PHP which is used to create an array. There are three types of array in PHP: Indexed array: The array which contains numeric index. Syntax: array( val1, val2, val3, ... ) Associative array: The array which contains name as keys. Syntax: array( key=>v 2 min read PHP count() Function The count() function in PHP is used to count the number of elements in an array or the countable properties of an object. The function returns an integer value representing the number of items present.Syntax:count($array, mode)In this syntax:$array (mandatory): Refers to the array, whose elements ar 3 min read PHP Array Functions Arrays are one of the fundamental data structures in PHP. They are widely used to store multiple values in a single variable and can store different types of data, such as strings, integers, and even other arrays. PHP offers a large set of built-in functions to perform various operations on arrays. 7 min read Like