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 can use reset() function if you want to traverse the array again using each().
Parameter: This function accepts a single parameter $array which is the input array in which we want to find the current key-value pair to which the internal pointer is currently pointing.
Return Value: This function returns the key-value pair of the current element of the input array $array. The key-value pair is returned in the form of a new array containing four elements. The first two elements with keys(1 and Value) are for the current element’s value, and next two elements with keys (0 and Key) are for the current element’s key. If the input array is empty or if the internal pointer has reached the end of the array then this function returns FALSE.
Input : each(array('Ram', 'Shita', 'Geeta')) Output : Array (  => Ram [value] => Ram  => 0 [key] => 0 ) Explanation: Here input array contain many elements but ram is the current element so the output contains its key and value pair.
Below programs illustrate the each() function in PHP:
Array (  => maya [value] => maya  => 0 [key] => 0 )
a => anny b => bunny c => chinky
- PHP | each() Function
- How to break _.each() function in Underscore.js ?
- Collect.js | each() Function
- D3.js selection.each() Function
- D3.js node.each() Function
- How to get the function name inside a function in PHP ?
- jQuery | Misc each() Method
- How to display bootstrap carousel with three post in each slide?
- How to place two bootstrap cards next to each other ?
- How to skip to next iteration in jQuery.each() util ?
- Sass @each Rule
- How to Add Image into Dropdown List for each items ?
- How to add unique Id to each record in your local/custom database in Node.js ?
- How to put items underneath each other flex box in Bootstrap 4 ?
- How to place two input box next to each other using Bootstrap 4 ?
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function