Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialadam blevins
Courses Plus Student 2,285 PointsHow do empty arrays work?
I am stuck on php datatypes exercise where it asks us to input an empty array name $colors. I got the other parts down with ease. I have watched the video at this point 6 times and apparently don't get it. I have typed in:
$colors = array(); which I thought was the answer.
I even tried an example from the video where the instructor talks about empty arrays:
$array_example = array(); but I used $array_colors = array();
I could use some information on what I am missing. Thanks.
5 Answers
Cody Evans
33,900 PointsYour first answer should be correct. I passed the challenge yesterday with the same answer.
$colors = array();
adam blevins
Courses Plus Student 2,285 PointsIf I had an error on my previous code I wouldn't be able to do step 4 which is empty array. You must complete the first step before it allows you to move on to the next task.
Kate Hoferkamp
5,205 PointsHave you tried to do the challenge again? The code challenge could of just had an error.
adam blevins
Courses Plus Student 2,285 PointsYes I got it this time. Here was the problem: when asked to create $bool = true that is the correct answer for that task which allows you to move on. But when you move on to create an empty array, $colors = array(); it will come up wrong because you didn't close out the previous line with a ; Once I put a ; at the end of $bool = true; I was able to pass.
Kate Hoferkamp
5,205 PointsAhh! Those darn ;'s! Get ya every time.
Nicklas Lind
3,619 PointsHeureka!
This is what fixed it for me:
Make the array BEFORE the code from the precious tasks and write the array like this:
$colors = array();
NOT like this:
$colors array = ();
Booya!
adam blevins
Courses Plus Student 2,285 Pointsadam blevins
Courses Plus Student 2,285 Pointswell its not working today. are you leave a space between array and ()?
Cody Evans
33,900 PointsCody Evans
33,900 PointsI just ran through the PHP Datatypes Challenge again. Seems to be working just fine with the code below.
$colors = array();
The only other possibility I can think of is you may have an error in your previous code that is causing this Task to fail.