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

Alex Watts
Alex Watts
8,396 Points

Why does the '$' have to be in front of a variable?

Hello,

I am new to PHP and am not sure why the dollar sign has to be used in front of a variable. Is it similar to jQuery, where by the dollar sign is short hand for a jQuery function? i have included an example below:

<?php

    $name = "Alex";

?>

5 Answers

lihaoquan
lihaoquan
12,045 Points

It is just a way to tell the PHP interpreter ( the "thing" that translates your code into actual instructions ) that you are creating a variable.

PHP is a Server Side Language, which means that all the logic is run on the server. In contrast, JQuery, a Javascript framework, is a Client Side Language, which means that all the logic is run on the client's web browser. They have nothing to do with each other, please don't confuse yourself. Hope it helps.

Alex Watts
Alex Watts
8,396 Points

Ok, so the dollar sign simply tells the interpreter that a variable is being created. I would like to test php on my iMac without having to upload my website to a server is there any way I could do this?

Thanks!

Grace Kelly
Grace Kelly
33,990 Points

You need to install a local server environment. You're using an iMac so you should use MAMP. There's a workshop on how to do this here :)

Grace Kelly
Grace Kelly
33,990 Points

no problem, glad to help!!

Mohsen Qaddoura
Mohsen Qaddoura
22,237 Points

The previous answers are all excellent. I just want to add that in PHP you use the dollar sign in front of the variable all the time not just at the time you declare it!