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.
Syntax
Parameter
- array array is required parameter. it is the input array to use.
Example
The following example show to how the each() function can be used in PHP.
<html>
<body>
<h3 style="color: brown;">each() function example in PHP</h3>
<?php
$array1 = array("Nitin", "Ravi", "Rajesh", "Arvind");
reset($array1);
while (list($key, $val) = each($array1))
{
echo "$key => $val<br />";
}
?>
</body>
</html>
|
Output
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