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 trialAlex Watts
8,396 PointsWhy 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
12,045 PointsIt 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
8,396 PointsThanks Mohsen.
Alex Watts
8,396 PointsOk, 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!
Alex Watts
8,396 PointsThanks Grace!
Grace Kelly
33,990 Pointsno problem, glad to help!!
Mohsen Qaddoura
22,237 PointsThe 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!