PHP tutorial-PHP variable

PHP variable

Variable is what the program used to store any values in computer’s memory such as text, number, date/time, etc.

Declaring and accessing variable

Before a variable is used, you must declare it. To declare a variable in PHP, you can use the following syntax:

To assign a value to the variable, write:


$yourname="Yuk Sovandara";
Note: The name of variable must start with a letter or underscore not a number.
To use the value of the variable, you need only specify $ and variable name.
$var="I like PHP very much.";
echo $var; // the value of var is used(display on the screen)
Note: It is no need to specify data type when you declare a variable in PHP.


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.