PHP for each loop

, by Prashant Gunjal





Foreach Syntax: $something as $key => $value
 here $something = name of array
         $key = index
         $value = actual value present in gthat location

This loop is very useful while collecting information from $_POST[] or from $_GET[] array

Program :
<html>
<head>
<title>PHP foreach</title>
</head>
<body>
<?php
    //Associative array
    $home["prashant"]="sangamner";
    $home["Bharat"]="Dhandharphal";
    $home["Vishal"]="Zole";

    foreach($home as $key => $result)
    {
        echo "<br>Home of $key is $result";
    }
?>
</body>
</html>

OUTPUT :

0 comments: