This forum is now read-only. Please use our new forums! Go to forums
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
Answer 514e271cadfe9a65c700172b
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.
3 comments
yep, that’s it! but shouldn’t arrays alow strings with more than one word?
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.
i got same error msg, thank you, i understand.
Answer 519cba781ba3cb3fb60076bd
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.
2 comments
That’s it.
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
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");
?>
5 comments
The track only asked for 3 of your friends names…
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?
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.
“at least” means that many or more. It should say “put exactly three elements.”
Well, true. I could be wrong, but I only used 3.
Answer 5151a3d0f820c03096001548
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 :)
Answer 5168004176ceca1518003b6b
Answer 53d7800d9c4e9de12500194a
Answer 548d967476b8fe67050063e6
I had the same space problem. Clearing the space makes it work.
Bad code:
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
yep, that’s it! but shouldn’t arrays alow strings with more than one word?
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.