PHP Variables

Variables are names given to the location in memory, and these locations are used to store information.

Creating PHP Variables

The PHP variable always starts with a $ sign, followed by the variable name.


$name = "jack";
$age = 21;
$height = 6.1;

After execution of this code, the variable $name holds the string value jack, the variable $age hold the integer value 21, and the variable name $height holds the float value 6.1.

PHP Variables

You can name a variable according to your convenience, like short names or more descriptive names (age, name, height).

Rules for creating a PHP variable:

  • A variable can’t start with a number.
  • A variable name always starts with the $sign.
  • A variable name must always start with a letter or underscore.
  • A variable name can only have underscores and alphanumeric characters.
  • A PHP variable is case sensitive.

Leave a Reply

Your email address will not be published. Required fields are marked *