A variable is a means of storing a value, such as text string “Hello World!” or the integer value 4. A variable can then be reused throughout your code, instead of having to type out the actual value over and over again. This is the tutorial to guide you how to create and use PHP variable.
Syntax:
$variable = value;
Example:
<?php $dcs_text = "techTutorialsOnline.com!";//variable that contains a string $dcs_x = 15;//variable that contains an integer $dcs_y = 15.5878;//variable that contains a floating point value ?>
Note: Variable names are case-sensitive, so use the exact same capitalization when using a variable. The variables $DCS_number and $dcs_number are different variables in PHP’s eyes.
php variable naming conventions
There are a few rules that you need to follow when choosing a name for your PHP variables.
- PHP variables must start with a letter or underscore “_”.
- PHP variables may only be comprised of alpha-numeric characters and underscores. a-z, A-Z, 0-9, or _ .
- Variables with more than one word should be separated with underscores.
$dcs_x = 15;//variable that contains an integer
- Variables with more than one word can also be distinguished with capitalization.
$dcsText = "techTutorialsOnline.com!";
This tutorial guides on how to use php variable. But if you have any question, raise it at Forum Section.