Creating variables in PHP

Variables are “containers” for storing information, which have a user-defined name. Using variables we can store some information and use later within the program.

In PHP we don’t need to specify the Datatype of a variable it automatically converts its type.

Syntax – 



Rules for PHP variables –

  • A variable starts with the $ sign, followed by the name of the variable.
  • A variable name must start with a letter or the underscore character.
  • A variable name cannot start with a number.
  • A variable name can only contain alphanumeric, character and underscores ( A-Z,0-9 and _ ).
  • Variable names are case sensitive ( $x and $X ) are two different variables.

Creating (Declaring) PHP variables –

  • PHP has no command for declaring a variable.
  • A variable is created the moment you first assign a value to it.

Example – 


$text = "Hello World";

echo $text;


Related Post

Spread the love

Be First to Comment

Leave a Reply

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