7.Putting it all together


#1


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.


<html>
  <head>
    <title>I am the King of Arrays!</title>
  </head>
  <body>
    <p>
      <?php
      // 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];
      ?>
    </p>
  </body>
</html>


#2

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

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

#3

That fixed it! Thanks!


#4

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