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 trial

PHP PHP Basics (Retired) PHP Datatypes PHP Datatypes Challenge

How 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
Cody Evans
33,900 Points

Your first answer should be correct. I passed the challenge yesterday with the same answer.

$colors = array();

well its not working today. are you leave a space between array and ()?

Cody Evans
Cody Evans
33,900 Points

I 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.

If 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
Kate Hoferkamp
5,205 Points

Have you tried to do the challenge again? The code challenge could of just had an error.

Yes 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
Kate Hoferkamp
5,205 Points

Ahh! Those darn ;'s! Get ya every time.

Nicklas Lind
Nicklas Lind
3,619 Points

Heureka!

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!