This forum is now read-only. Please use our new forums at discuss.codecademy.com.

728 points
51645c31cab5f44c300006d4_862629797
Submitted by
Elena
about 6 years ago

Parse error: syntax error, unexpected T_FOREACH on line 36

Hello! Here is my code:

$myCloths = array('dress' => 'pink',
'shirt' => 'blue',
'pants' =>'white')
foreach ($myCloths as $word) {
echo "In my closet there are:"." ".$word." ".$myCloths;

Although I passed this lesson, I receive this error. Could someone explain me why? Thanks!


2 votes

permalink

I found the following problems;

1 - missing ";" at the end of the Array.

2 - missing brackets at the end of the foreach conditional.

3 - the complete syntax for foreach is "foreach ($ myArray = the $ arg1> arg2) {statement. $ Arg1, statement. Arg2)".

Below .... I found a way to run the code...

  $myCloths = array('dress' => 'pink',
    'shirt' => 'blue',
    'pants' =>'white');
    foreach ($myCloths as $word=>$word2) {
    echo " In my closet there are:"." ".$word2." ".$word;}

562 points
Ca54f9e63e0c6b277f330482bc85e3b9?s=140&d=retro
Submitted by
Fábio Freire
almost 6 years ago

1 Comment

116108cc049b54fa4cadcefb3de32e1a?s=140&d=retro alankar padman almost 5 years ago

then why is it that it is correctly executed by codeademy interpreter? When I try the same code on any other online interpreter it throws this error.


0 votes

permalink

I'm assuming you closed the last bracket right?

965 points
247db662c271fe67d41f4c6284fa9b56?s=140&d=retro
Submitted by
Brettski
about 6 years ago


0 votes

permalink

There is no ';' at the end of your association array. Your code should be:

$myCloths = array('dress' => 'pink',
'shirt' => 'blue',
'pants' =>'white');

You also need a closing bracket at the end of your foreach.

1295 points
57113c6114f3ef531b000126_28716191
Submitted by
Andy Petrzilka
almost 6 years ago