7/7 I passed but Need Guidance with Aligning Print


#1

<?php
// On the line below, create your own associative array:
$myArray = array(
'degrees' => '98F',
'fun' => 'unlikely',
'disposition' => 'frustrated');

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

The above code is correct, however my print looks like this:

98Fdegrees 98F
fun unlikely
disposition frustrated

I'd like degrees 98F to align on the second row with the other foreach() keywords and values. Where would I place a bracket?


#2
 echo $myArray['degrees'];

just needs an added line break:

 echo $myArray['degrees'] . '<br>';

A tiny clarification with regards to naming variables...

foreach($myArray as $keywords=>$values) {

The variable names above imply plurality, when in fact each is a singular term which is better written that way so it is interpreted correctly when reading the code:

foreach ($myArray as $key => $value) {

Just saying...


#3

Thank you! I will change it to keyword and value. :smile_cat: