Help me please - Lesson 4 / Advanced Arrays


#1







<?php
// Ceci est un tableau utilisant des entiers comme indexe...
$myArray = array(2012, 'blue', 5, 'BMW');

    // ... et voici un tableau associatif :
    $myAssocArray = array('year' => 2012,
                    'colour' => 'blue',
                    'doors' => 5,
                    'make' => 'BMW');
        
    // Ce code va afficher "blue".
    echo $myArray[1];
    echo '<br />';
    
    
    echo 'J'ai une voiture'.'$myAssocArray['year'].''.$myAssocArray['make'].'et possède'.$myAssocArray.['doors'].'portes.';
   
    
  ?>
</p>


it prints an error message

Oups, merci de réessayer. Affichez une phrase incluant l'année de fabrication de votre voiture, sa marque, son nombre de porte. On sait déjà qu'elle est bleu !

Please help me to solve this problem . thanks



#2

Is there something you would like to ask?


#3

Yes please, I have problem with associated arrays.

echo 'J'ai une voiture'.'$myAssocArray['year'].''.$myAssocArray['make'].'et possède'.$myAssocArray.['doors'].'portes.';

it prints an error message. I can't proceed to next lesson.

Thanks in advance


#4

PHP is beyond me, especially in a foreign language, but perhaps we have a chance together.

Something that stands out is:

echo 'J'ai une voiture'

It looks to me like the string ends after the J - you probably need to escape the apostrophe (')


#5

Thanks, the problem stays there. If I remove " ' " the whole paragraph gets yellow color .


#6

There's another apostrophe that looks out of place to me.
It also complains about unexpected [

I put some carets (4 of them, only 2 visible without scrolling to the right) where things look off to me:

echo 'J'ai une voiture'.'$myAssocArray['year'].''.$myAssocArray['make'].'et possède'.$myAssocArray.['doors'].'portes.';
       ^                ^                                                                          ^       ^

#7

I removed but the error stays there.

echo 'j ai une voiture'. $myAssocArray['year'].'.$myAssocArray['make'].'et possède'.$myAssocArray.['doors'].'portes.';

error message on the screen-

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on line 22


#8

You only fixed 2 of the 4 things I pointed at!

You've also changed a '' to just ' - they have to come in pairs.


#9

Thanks a lot it solved my problem.

echo 'j ai une voiture'. $myAssocArray['year']. $myAssocArray['make'].'et possède'.$myAssocArray['doors'].'portes.';

print on the screen-

j ai une voiture2012BMWet possède5portes.