Oops, try again. It looks like 'one=>1' is part of $myArray, but it wasn't printed to the page!


#1

I can't figure out what's wrong with my solution to this problem. I continually get the following error:

Oops, try again. It looks like 'one=>1' is part of $myArray, but it wasn't printed to the page!

when running this code:

<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('one' => '1', 'two' => '2');

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

I don't get it. Is this a bug? It's really unfortunate if so; I'm 98% finished and really wanted to finish this.


#2

I'm having the exact same issue...My syntax is exactly the same and I can't figure out why it doesn't like my answer. I'm guessing it's a bug. I JUST WANT THE BADGE CODE ACADEMY DON'T TOY WITH ME LIKE THIS.


#3

Saw another post with a bug fix, just format your associative array so it's written on different lines and it should pass. Stupid, but it worked for me!


#4

thanks designace95292, that worked!


#5

mine works but won't let me pass ....

  // On the line below, create your own associative array:
    $myArray = array(array('king of diamonds',13),
                    array('queen of hearts',12),
                    array('ten of spades',10));

  // On the line below, output one of the values to the page:
 echo "Playing with the " .$myArray[1][0]. ".";
 echo "<br />";
      
  // On the line below, loop through the array and output
  // *all* of the values to the page:
 $i = 0;
 foreach ($myArray as $card=>$value) {
     $length = count($myArray);
     echo "The " .$myArray[$i][0]. " has a value of " .$myArray[$i][1]. ".<br />";
     $i++;
     }

#6

Change the line inside your foreach loop to this:

echo $number . "=&gt" . $item . '<br />';


#7

Worked for me too, Thank you! :slightly_smiling:


#8

It works like a charm. Thank you!


#9

I also had to remove all other output from my page, e.g. the result of

// On the line below, output one of the values to the page:
echo "<p>" . $myArray['first'] . "</p>";

#10

try this:

echo $myArray['o1ne']

The intended error in 'o1ne' may let you pass this lesson, it works for me.


#11

Thanks for all this info, guys. I had a perfect bit of code that accurately placed three of my PHP-related annoyances on the webpage from the 2D array I made, which only failed because Codecademy said that something wasn't printed, when I could clearly see that it already was. I had to go to this thread and cheat to get through.


#12

That's because you have a multi-dimensional array, not an associative array.


#13

You are right! THAT's the ONLY solution..


#14

why it works when you add =&gt ???


#15

I have tried all possible methods (simple array as suggested by Hint, Associative Array, and Multi-Dim) and still get the same error. I have also tried with '+&gt' in whitespace and filling whitespace with ':', all to no avail. Is there something else wrong with my code?


#16

nvm...after removing all the details, it works with =&gt in the whitespace. The lesson will only pass with single-word keys and values even though you may have created a more elaborate program that displays perfect output.


#17

Thankyou...it works!:joy:


#18

You think they would have fixed by now…I wasted a lot of time.


#19

I can confirm that I too wasted a lot of time.


#20

I had the same problem…
I don’t know why, but it’s working! I mean (thing with diferrent lines)