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 PHP Arrow Functions PHP arrow functions are a shorthand syntax for anonymous functions. It was introduced in PHP 7.4, which provides a shorter way to write anonymous functions. They allow you to create functions with fewer lines of code while maintaining functionality. They provide an easy-to-read syntax, particularly 5 min read PHP current() Function The current() function is an inbuilt function in PHP. It is used to return the value of the element in an array which the internal pointer is currently pointing to.The current() function does not increment or decrement the internal pointer after returning the value.In PHP, all arrays have an interna 2 min read PHP explode() Function The explode() function is an inbuilt function in PHP used to split a string into different strings. The explode() function splits a string based on a string delimiter, i.e. this function returns an array containing the strings formed by splitting the original string. Syntax:array explode(separator, 3 min read PHP key() Function The key() function is an inbuilt function in PHP which is used to return the index of the element of a given array to which the internal pointer is currently pointing. The current element may be starting or next element which depends on the cursor position. By default cursor position is at zero inde 2 min read Like