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 Arrays and Control Structures PHP Arrays Associative Quiz

Danielle Evans
Danielle Evans
2,282 Points

Hi, maybe you know...

The 4th element has no value attached to it. So how does it have a key? And how does it have a key of 0?

Quiz Question 5 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?

1 Answer

Benjamin Larson
Benjamin Larson
34,055 Points

Some highlighted notes from the: PHP Manual: array

  1. PHP arrays can contain integer and string keys at the same time as PHP does not distinguish between indexed and associative arrays.

  2. The key is optional. If it is not specified, PHP will use the increment of the largest previously used integer key.

So when no key is given, PHP defaults to a numeric index starting at 0.

Danielle Evans
Danielle Evans
2,282 Points

Thank you very much, I appreciate you answering.