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 trialOliver Chalk
3,615 Pointsecho $name is not working
I cannot get php to echo the variable
<?php
$name = "Mike";
?>
<?php
echo $name;
?>
4 Answers
Marcus Parsons
15,719 PointsHi Oliver,
The code you pasted here to the forums works perfectly for the challenge. The simplest solution is to just place both inside the PHP block. But, yours is not only valid but how PHP is often used with various code blocks. Perhaps recopy the code you posted and then go through the challenge again.
<?php
$name = "Mike";
echo $name;
?>
Abe Layee
8,378 PointsI don't know much about php, but you should have one php code like this.
<?php
$name = "Mike";
echo $name; //all php codes here
?>
Marcus Parsons
15,719 PointsNo, you don't have to have one PHP code block. It is the simplest solution, but it's not the only solution.
Abe Layee
8,378 PointsThank again Marcus Parsons . I appreciate your help a lot. I am planning on taking php track after the Front End track.
Marcus Parsons
15,719 PointsPHP is a fun language and one that works really well with JavaScript because they share a lot of the same syntax. I find it easy to switch between PHP and JavaScript development because of that. There are some languages where that's not the case cough Ruby cough lol
Abe Layee
8,378 Pointslol. I asked this Rail Developer at a MeetUp about choosing PHP over Ruby and he told me PHP is going to be dead few years from now. I felt discourage after that and, I decided to go with Ruby, but not anymore. I found PHP very power. By me knowing PHP, my life will become a lot easiest when creating a Wordpress site or any site.
Marcus Parsons
15,719 PointsI really don't see that happening to be honest. You have Wordpress and Laravel and other PHP frameworks that aren't going to be disappearing anytime soon. It does have its quirks, but I haven't heard of a language that doesn't have any lol