Bug in Accessing Associative Arrays


Whatever I put in, I get a fault and the error messages don't make sense. One thinks that I did not use [] and the other one thinks I've only said that it's blue. Is this a bug?

echo 'I have a ' . $MyAssocArray['year'] . ' ' . $MyArray[3] . '. It has ' . $MyAssocArray['doors'] . ' doors and is $MyArray[1] . '.';

Oops, try again.
Try talking about the year your car was made, its make, or the number of doors it has. We already know it's blue!

Replace this line with your code.



change it
because they already know it's blue! try to print year not the color :slight_smile:


either way, the blue doesn't make or break the code. It's getting an error either way.


can you please post a screen shot or entire code?


Sure thing!

    // This is an array using integers as the indices...
    $myArray = array(2012, 'blue', 5, 'BMW');

    // ...and this is an associative array:
    $myAssocArray = array('year' => 2012,
                    'colour' => 'blue',
                    'doors' => 5,
                    'make' => 'BMW');
    // This code will output "blue".
    echo $myArray[1];
    echo '<br />';
    // Add your code here!
      echo 'I have a ' . $MyAssocArray['year'] . ' ' . $MyArray[3] . '. It has ' . $MyAssocArray['doors'] . ' doors.'; 


'M' should be lowercase because

your variable name is


but you wrote to echo