Using Foreach To Iterate Through An Array

 
    <?php
     $prog_language[] = "PHP";
     $prog_language[] = "C";
     $prog_language[] = "C++";
     $prog_language[] = "Java";
     $prog_language[] = "Forth";
     $prog_language[] = "Perl";
     $prog_language[] = "Python";
     $prog_language[] = "Ruby";
 
     foreach($prog_language as $language)
     {
          if(!strcmp($language, "PHP")){
               print("<b>" . $language . "</b> <br />");
          }else{
               print($language . " <br />");
          }
     }
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.