Hepl Please - Problem on 'Putting it All Together'


#1

hello,

that's my code and at the least foreach I printed all the elements of my loop; The problem is the error message of codeacademy :"Oops, try again. It looks like 'Key1=>val1' is part of $myArray, but it wasn't printed to the page! ", but I printed it!

so how can I solved it?
$myArray = array('Key1' => 'val1', 'key2' => 'val2');

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

Thanks everyone!

//
//
//I am the King of Arrays!
//
//
//


// <?php
// On the line below, create your own associative array:
$myArray = array('Key1' => 'val1', 'key2' => 'val2');

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


*/


#2

Hi,
You don't necessarily have to echo $key . ' ' . $value; maybe you can try an other sentence. Sometimes codecademy can bug with just a different sentence .
Tell me if that worked otherwise i'll try to find out the problem/


#3

Hi,

thank you for your reply!
I try differently but it doesn't work! that's annoying !


#4

Hi,
I encountered same problem, and I could resolve it.
codecademy expected you to print 'key=>value', so you replace

echo $key . ' ' . $value;

in your code with below code.

echo $key . '=& gt;' . $value;

In this code I wrote white space between '=&' and 'gt;', but when you write you must not write white space. Then, you can print '=>'.

I'm Japanese, so not good to write English. If you can't understand what I mean, please let me know. Sorry.


#5

thank you it works perfectly!


#8

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