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

Arrays Forum

View Course » View Exercise

973 points
50ef629d5df182d48e004e54_996279525
Submitted by
Stuart Phillips
about 4 years ago

Code not working

I changed the [ to { as per instructions and get a message in the results field "Parse error: syntax error, unexpected '{', expecting '(' on line 8"

My code;


Accessing Elements



<?php
$tens = array{10, 20, 30, 40, 50};
echo $tens[2];
?>


1 vote

permalink

I think the reason it is not working is because the array is in brackets. Try replacing those brackets with parentheses, like this, follow the code exactly as it worked for me:

<?php

$tens=array(10,20,30,40,50);
echo $tens[2];

?>

1023 points
55aa6d8676b8fe6630000823_355841192
Submitted by
Erwin dela Torre Novo
about 4 years ago

2 Comments

55aa6d8676b8fe6630000823_355841192 Erwin dela Torre Novo about 4 years ago

Or you can also do it like this:

<?php

$tens=array(10,20,30,40,50);
echo $tens{2};

?>

What is important is your assignment of array values to the variable. The array values should be contained inside parentheses and not curly braces. Hope this helps you...

51b0e05452f8631243002008_754409394 Ahmet Toktay about 4 years ago

Erwin's code is true, Stuart's code is false. Switch the {}'s, it's true is: ()