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

Bummer! Unfortunately, that answer is incorrect

How is this answer 0, I thought it was May, since the I counted it as the 4th => as the key?

1 Answer

Antonio De Rose
Antonio De Rose
20,884 Points

Try run this code, if you have setup php locally, and see the output, I have anyway put the output

<?php

$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"); 

echo "<pre>";
print_r($myArray);
echo "</pre>";

//the below would be the output you get, if you run it in a localhost

/*Array
(
    [January] => Winter
    [February] => Winter
    [March] => Spring
    [0] => April
    [May] => Spring
    [June] => Summer
    [July] => Summer
    [August] => Summer
    [September] => Fall
    [October] => Fall
    [November] => Fall
    [December] => Winter
)*/

//just to get more confidence, take 2 more keys out to see, what would be the keys represent
//here am taking the July out, and December out.
//for that the code would be as below

$myArray = array("January" => "Winter", "February" => "Winter", "March" => "Spring", "April", "May" => "Spring", "June" => "Summer", "Summer", "August" => "Summer", "September" => "Fall", "October" => "Fall", "November" => "Fall", "Winter"); 

//for the right above, you get the, below answer.

/*Array
(
    [January] => Winter
    [February] => Winter
    [March] => Spring
    [0] => April
    [May] => Spring
    [June] => Summer
    [1] => Summer
    [August] => Summer
    [September] => Fall
    [October] => Fall
    [November] => Fall
    [2] => Winter
)*/

//what confirms here, when you have an array, with the absence of a key, the first absent one
//will take 0 for key, as arrays are programmed to start from 0, and then blanks will be
//in ascending order.

?>