Learning PHP and MySQL

Example 06-04 Display the contents of an array using a loop

<?php
$shapes
=array('Soda Can'  =>  'Cylinder',
              
'Note Pad'  =>  'Rectangle',
              
'Apple'  =>  'Sphere',
              
'Orange'  =>  'Sphere',
              
'Phonebook'  =>  'Rectangle');
foreach (
$shapes  as  $key  =>  $value)  {
  
print"The $key is a $value.<br>\n";
}
?>

Posted by on 08/07 at 10:20 AM

Next entry: Example 06-05 Counting the elements in an array

Previous entry: Example 06-03 Displaying one value from an array

<< Back to main