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 PHP Basics (Retired) PHP Data & Structure PHP Variables

Oliver Chalk
Oliver Chalk
3,615 Points

echo $name is not working

I cannot get php to echo the variable

index.php
<?php 

$name = "Mike";

?>
<?php 

echo $name;

?>

4 Answers

Hi 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
Abe Layee
8,378 Points

I don't know much about php, but you should have one php code like this.

<?php 

$name = "Mike";
  echo $name;  //all php codes here

?>

No, you don't have to have one PHP code block. It is the simplest solution, but it's not the only solution.

Abe Layee
Abe Layee
8,378 Points

Thank again Marcus Parsons . I appreciate your help a lot. I am planning on taking php track after the Front End track.

PHP 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
Abe Layee
8,378 Points

lol. 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.

I 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