Using foreach to Iterate through an Array : Array Loop « Data Structure « PHP






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 />");
          }
     }
?>

           
       








Related examples in the same category

1.Looping through an Enumerated Array
2.Looping Through a Compact Indexed Array Using for and count()
3.Looping Through a Multidimensional Array
4.Looping Through a Sparse Array
5.Looping Through an Associative Array with foreach
6.Looping Through the $_SERVER Array
7.Looping through child elements with foreach()
8.Looping through identically named elements with foreach()
9.Looping with foreach()
10.List array values