How to use each in PHP
In this article, I will explain how the each() function can be used in PHP.
each() function in PHP
- The each() function is used to return key and value of the current element.
- The each() function moves the internal pointer forward.
- In each() function, If there are no more array elements, it returns FALSE.
- The each() function is returned in four element array, two elements for element value and rest two elements for element key.
- array array is required parameter. it is the input array to use.
The following example show to how the each() function can be used in PHP.
<h3 style="color: brown;">each() function example in PHP</h3>
$array1 = array("Nitin", "Ravi", "Rajesh", "Arvind");
while (list($key, $val) = each($array1))
echo "$key => $val<br />";
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here