This forum is now read-only. Please use our new forums! Go to forums
banner
Close banner
Why wont this work??Always shows some error like did you replace [ ] with {} when i already have
Answer 53fac56780ff337ac7008734
4 votes
You have a space after {2} take that space out and put ; right after {2}. It will work. <?php $tens = array(10, 20, 30, 40, 50); echo $tens{2};
?>
Answer 5413c3547c82caa4ba001a7f
0 votes
You need to put {2} in normal braces, like [2].
Answer 542c596d7c82caee44001360
0 votes
Insert a space after [2] eg: echo $tens[2] ;
Answer 54652de752f863df91000100
0 votes
Very contradicting answers here. Fact 1: While using arrays, to access the index of the value, you type $arrayName[i] with i being the index position - 0 to however many items you have.
Fact 2: White space rarely matters and when it does, the accompanying code documentation will usually warn you of it. So, both $tens[2]; and $tens[2] ; and even $tens[2] ; will work just fine
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency