Learning PHP and MySQL

Example 06-06 Using sort to alphabetize

<?php
$shapes  
=  array("rectangle""cylinder""sphere");
sort($shapes);
//The  foreach  loop  selects  each  element  from  the  array  and  assigns  its  value  to  $key
//before  executing  the  code  in  the  block. foreach ($shapes  as  $key  =>  $val)  {
echo "shapes[" $key "]  =  " $val "<br>";
}
?>

Posted by on 08/07 at 10:21 AM

Next entry: Example 06-07 Creating a multidimensional array

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

<< Back to main