Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Introducing arrays question

Now let’s add another letter. Add a fourth element to the array with a value of “R” (my personal favorite). When you preview the code, notice that the count of letters increases and the new letter is added to the list automatically.

When i type in the code it fails on task 4, since i need to add a fourth value to pass it further.

<?php

$letters = array ("D","G","L","R"); echo "My favorite "; echo "3"; echo " letters are these: "; foreach ($letters as $letter){ echo $letter; } echo ".";

?>

What to do? =)

3 Answers

you must change the second echo statement to display the number of elements in the array.
echo "3"
you must change the "3". try to use a function that counts all elements in an array
learn this [http://php.net/manual/en/function.count.php]

I solved it, i was too fast not reading the instructions! Thanks!

<?php

$letters = array("D","G","L","R"); echo "My favorite "; echo "4"; echo " letters are these:"; foreach($letters as $letter){ echo $letter; } echo ""; echo ".";

?>

THX HILAS FOR THE EXPLANATION.