7.Putting it all together


I'm not sure what I'm doing wring. Code prints to screen but getting "Oops, try again. It looks like 'Dogs=>cool' is part of $myArray, but it wasn't printed to the page!" error.

    <title>I am the King of Arrays!</title>
      // On the line below, create your own associative array:       
        $myArray = array("Dogs"=> "cool", "Cats"=>"okay", "Horses"=> "also cool");

      // On the line below, output one of the values to the page:
     $length = count($myArray);
      // On the line below, loop through the array and output
      // *all* of the values to the page:
     foreach($myArray as $pets=> $animals){
         echo  $pets . ' are ' . $animals . '. '; 
            $myArray[0] = "Dogs";
            echo $myArray[0];


Try spreading your array over multiple lines, as I suspect there's a bug there.

$myArray = array("Dogs"=> "cool", 
   "Horses"=>"also cool");


That fixed it! Thanks!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.