Variables in PHP

  • Variables are used for storing a value, like text strings, numbers or arrays. All variables in PHP start with a $ sign symbol. A variable name must start with a letter or an underscore "_"
  • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
  • A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)
Example:  $test1 or $_test1 [Best Practice]
$1test or $1_test [Bad Practice]
<?php
$test="Hello World!";
$y=16;
echo $test;
echo $y;
?>

Click to see output