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

Why is the answer 0?

Quiz Question 1 of 5 $myArray = array("January" => "Winter", "February" => "Winter", "March" => "Spring", "April", "May" => "Spring", "June" => "Summer", "July" => "Summer", "August" => "Summer", "September" => "Fall", "October" => "Fall", "November" => "Fall", "December" => "Winter"); What is the KEY of the fourth element?

--I don't understand why the answer is zero.--

4 Answers

Steven Parker
Steven Parker
231,140 Points

:point_right: When no key is specified, the key is the next available integer value.

Since the fourth item ("April") has no explicit key (there's no "=>" operator), it is given a sequential integer value as the key. And since the previous items all have explicit string keys, the value 0 is still available and becomes the key for the value "April".

Oh, ok I get it now. Since 0 is the next available integer and 'April' has no specific key. 0 becomes the key of "April". But if 0 and lets say 1 had already been used then "April" would be assigned the Key of 2... right? If my understanding is correct please let me know.

Charlie Sattgast
Charlie Sattgast
7,205 Points

To the good folks at Treehouse. I didn't appreciate being tested on the material that's found in the video FOLLOWING the quiz, not prior to the quiz. Takes me back to the 7th grade math teacher who did that to us all year. It's more frustrating than a good teaching tool. Please move the quiz to the right one place so it tests on material that's actually been covered in the class.

Tuan Phan
Tuan Phan
10,825 Points

You will study that in the next video at 4:51 above... Yes, in the NEXT video.

That wasn't the actual problem guys, the question specifically said "What is the KEY of the fourth element?" but the answered ended up being what the actual KEY VALUE was, which is 0. The actual KEY for the fourth element is APRIL.