7. Putting it all together


#1

Does anybody know why this won't work?

<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('Focusrite'=>'interface', 'BenQ'=>'monitors', "Adam"=>"speakers");

      // On the line below, output one of the values to the page:
    echo $myArray['Focusrite'];
        
      // On the line below, loop through the array and output
      // *all* of the values to the page:
    foreach ($myArray as $make=>$equipment){
        echo $equipment . ': ' . $make . '.';
    }
    ?>
    </p>
  </body>
</html>

#2

anybody? I get this error: Oops, try again. It looks like 'Focusrite=>interface' is part of $myArray, but it wasn't printed to the page!


#3

I hope this will help you

  <?php
  // On the line below, create your own associative array:
    $myArray = array('Focusrite'=>'interface',
                        'BenQ'=>'monitors',
                        'Adam'=>'speakers');

  // On the line below, output one of the values to the page:
 echo $myArray['Focusrite'];
 echo '<br/>';
      
  // On the line below, loop through the array and output
  // *all* of the values to the page:
     foreach ($myArray as $make=>$equipment){
    echo $equipment . ': ' . $make . '.<br/>';
        }
 
  ?>

#5

Try print instead of echo.


#6

The answer is in one of the other threads as well as from gracie:

change: $myArray = array('Focusrite'=>'interface', 'BenQ'=>'monitors', "Adam"=>"speakers");

to

$myArray = array('Focusrite'=>'interface',
'BenQ'=>'monitors',
'Adam'=>'speakers');


#7

@squeakasaur Thanks for the tip I was puzzled why my code won't pass.


#8

Thanks for the tips guys. In the end my answer was fine - tried submitting it again a few days later and it was accepted! Must have been a bug on Codecademy's side.