Iterating an Array with foreach and while/list/each : Array List : Data Structure PHP Source Code


PHP Source Code » Data Structure » Array List »

 

Iterating an Array with foreach and while/list/each



<?php
     $pc_parts = array();
     $pc_parts["Memory""256 MB";
     $pc_parts["CPU""Athlon Thunderbird";
     $pc_parts["Video Card""Matrox";
     $pc_parts["Hard Drive""IBM";
   
     foreach($pc_parts as $part_type => $part_name) {
          $buf = sprintf("Part name is: <strong>%s</strong> Part value is: 
                          <strong>%s</strong>", $part_type, $part_name);
          echo $buf . "<br />";
     }
     echo "<br /><br />";
   
     reset($pc_parts);
     while (list($part_type, $part_name= each($pc_parts))
     {
          $buf = sprintf("Part name is: <strong>%s</strong> Part value is: 
                          <strong>%s</strong>", $part_type, $part_name);
          echo $buf . "<br />";
     }
?>

           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Data Structure
» Array List