Arrays in PHP - I'm lost


#1

Sorry I have been gone so long. I will try to be more active and help people :slight_smile:

Anyway, I am lost. This exercise asks me to "Create an array called $friends and put the names of three of your friends in it. Since each friend's name is a string, make sure to write it between quotes."

Here is my code:

<html>
  <head>
    <title>My First Array</title>
  </head>
  <body>
    <p>
      <?php
      $friends = array("I\'ve", "No", "Friends");
      ?>
    </p>
  </body>
</html>

My error message is:

"Oops, try again. Did you remember to put at least three elements in your array? Make sure each one is a string in quotes!"

I tried it on both Edge and Chrome, and neither worked. I have also tried refreshing.

My question is: Did I make a mistake, or is it a mistake on Codecademy's side? If I made a mistake, please point it out so I may correct it.

Thank you all in advance for any help you may give me :slight_smile:


#2

Why not make it just simple? Your code really should work but you know, let's just do as said.

<html>
  <head>
    <title>My First Array</title>
  </head>
  <body>
    <p>
      <?php
        $friends = array("Me", "No", "Friends");
      ?>
    </p>
  </body>
</html>

#3

Thank you for the suggestion, but I have already tried using simple words without the backslash.


#4

Okay, that's fine.

Have fun coding. :smile:


#5

The problem with your code is in line 8:

Line 8: $friends = array("I\'ve", "No", "Friends");

The backslash in PHP (as well as many programming language) is called an "Escape character" which is used to add a special meaning to the character following it. For example:
\n is used to add a newline.

So here you have a backslash followed by an apostrophe, which is most likely to be causing the problem.

Please let me know if that helped!