This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Pedro Morais
about 11 years

why is my array wrong?

  <?php
  $friends = array ('Jules', 'Vincent Vega', 'Butch');
  ?>

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

if i do it like this:

  <?php
  $friends = array ('Jules', 'Vincent Vega', 'Butch');
  print_r ($friends);
  ?>

it continues with the same error message but the array is printed in screen:

Array ( [0] = Jules [1] = Vincent Vega [2] = Butch )

the result is the same with (‘ ‘) or (“ “) in the strings.


this exercise worked when i inserted “do”, “re”, “mi” as friends. it didn’t allow other names.

Answer 514dbb4ae2175a5aa4000367

6 votes

Permalink

The reason why the first one didn’t worked was because you had space between Vincent Vega. You’re only allowed to have 1 name without space. :P

points
Submitted by Laampan
about 11 years

2 comments

Pedro Morais about 11 years

yep, that’s it! but shouldn’t arrays alow strings with more than one word?

Curran almost 11 years

Arrays do allow strings with more than one word, it is just the exercise that is giving the error. What you put is valid PHP, just not in this exercise.

Answer 514e271cadfe9a65c700172b

3 votes

Permalink

Yeah, you have have spaces in the names.

Wont work : “ $friends = array( “This”, “Will Not”, “Work” ); “ BECAUSE THERE IS A SPACE.

Will Work : “ $friends = array( “This”, “Will”, “Work” ); “ BECAUSE THERE IS NO SPACES IN BETWEEN THE WORDS / NAMES.

points
Submitted by SirenNinja
about 11 years

3 comments

Pedro Morais about 11 years

yep, that’s it! but shouldn’t arrays alow strings with more than one word?

SirenNinja about 11 years

1 word per 2 quotation marks. That’s how you create more than 1 word. It should be “ More That 1 Word” but, sadly it’s not.

hao about 11 years

i got same error msg, thank you, i understand.

Answer 519cba781ba3cb3fb60076bd

3 votes

Permalink

For those who can’t understand why their code does not pass: the exercise will only allow you to go on if you have exactly 3 elements in your array.

In the error reason output, “at least” suggests that you could put more than 3 elements in your array, that shoud be corrected.

points
Submitted by Akian
almost 11 years

2 comments

jlancasterwashcald.com almost 10 years

That’s it.

qbert007 about 9 years

That was an infuriating 15 minutes, because I had one extra name in the string, so there were “at least” three. Instead of “three”.

Answer 51547d03b4ad53870300016b

2 votes

Permalink

Same problem. Only one word per quote, just first names. Tried saving and refreshing. No luck. This PHP track seems rife with errors.

  <?php
    $friends = array("Justin", "Dan", "Luke", "Brian");
  ?>
points
Submitted by David Karasek
about 11 years

5 comments

SirenNinja about 11 years

The track only asked for 3 of your friends names…

David Karasek about 11 years

Yeah, for some reason I thought it said 3 or more. But, if that is the error, couldn’t it output that as the reason?

SirenNinja about 11 years

It does. “ Did you remember to put at least three elements in your array? “

It tell’s you that you need to put 3. No more or less.

Anarcho Nomad over 10 years

“at least” means that many or more. It should say “put exactly three elements.”

SirenNinja over 10 years

Well, true. I could be wrong, but I only used 3.

Answer 5151a3d0f820c03096001548

1 vote

Permalink

For me I was sure my code was right but it wouldn’t pass. Just saving and refreshing the page made it work, some of you may want to try that :)

points
Submitted by David Munday
about 11 years

Answer 5168004176ceca1518003b6b

1 vote

Permalink

This is the answer.

points
Submitted by patel17
about 11 years

Answer 53d7800d9c4e9de12500194a

0 votes

Permalink

Mine worked only with

points
Submitted by Tiago
over 9 years

Answer 548d967476b8fe67050063e6

0 votes

Permalink

I had the same space problem. Clearing the space makes it work.

Bad code:

points
Submitted by Joseph Finch
over 9 years