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 trialMarkus Søe
6,391 PointsCan I echo multiple numbers?
I wanted to echo "Hello" from my variable $greeting, but I don't know the syntax $greeting = "Hello, Friends!";
My experiments: echo $greeting{0+1+2+3+4}; echo $greeting{0,1,2,3,4};
2 Answers
Ted Sumner
Courses Plus Student 17,967 PointsI am not sure what you are attempting to accomplish and the structure of your variable. It is an array? If so, you could manually enter the array index like this:
<?php
echo $greeting[0];
echo $greeting[1];
//etc
Note, the above example would put them all on the same line with no space between.
Or if you want them all, this would likely be a better solution:
<?php
foreach ($greeting as $greet) {
echo $greet;
}
I can tailor my response with some more information.
Ted Sumner
Courses Plus Student 17,967 PointsIf you want just spaces, you add the space in the echo like this: echo $array[0] . ' ';
or like this echo "$array[0] ";
or add a space to the echo in the foreach loop. If you want it on a new line, I recommend using an html break tag.
Markus Søe
6,391 PointsMarkus Søe
6,391 PointsThank you for answering!
How do I get a space in between?