Variables in PHP

 

Variables in PHP

Variables are containers that can store information which can be manipulated or referenced later by the programmer within the code.

 

In PHP, we don’t need to declare the variable type explicitly. The type of variable is determined by the value it stores. There are some important things to know about variables in PHP.


  • All variables should be denoted with a Dollar Sign ($)
  • Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.
  • Variable names can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).
  • Variables must start with a letter or the underscore “_” character.
  • Variables are case sensitive
  • Variable names cannot start with a number.

 

For Example:

<?php
$txt = "Hello world!";  # Type String
$x = 5;                        # Type int
$y = 10.5;         # Type Float
?>