What's the purpose of the hint?


#1


https://www.codecademy.com/courses/web-beginner-en-QnQrd/0/7?curriculum_id=5124ef4c78d510dd89003eb8#


"When using the for loop, you should count the length of the array first, using count().

Otherwise, for each value in the array, the computer will have to count the length again."

Is this just a hint for normal arrays?
So I have not to use it for the associative array which I just created.?

<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('small' => 'tablet',
                                    'medium' => 'laptop',
                                    'large' => 'desktop / personal computer');

      // On the line below, output one of the values to the page:
        echo 'My favourite computer is ' . $myArray['medium'] . ' !<br><br>';
          
      // On the line below, loop through the array and output
      // *all* of the values to the page:
        echo 'Types of computers:<br>';
        foreach ($myArray as $typeof=>$component) {
           echo '- as ' . $typeof . ' type we use ' . $component . '<br>'; 
        }
     
      ?>
    </p>
  </body>
</html>


#2

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