You are currently viewing How to Define Variables in PHP
  • Post category:PHP

How to Define Variables in PHP

Define Variables in PHP

In this article, we will discuss how to define variables in php. In PHP variables are something different to define compared to other languages.

Rules for PHP variables

  1. The best way to store data in PHP is to use variables. We should start the variable with the $ dollar sign.
  2. A variable name can consist of numbers, letters, and underscores, and no other special character is allowed. The second character must be a letter or underscore.
  3. If the underscore is the second character, then an alphabet should occur as the third character.
  4. No size limit to create PHP variables.
  5. No keyword should be used as a variable.
  6. PHP variables are case-sensitive.
  7. Variables in PHP do not have intrinsic types – a variable does not know in advance whether it will be used to store a number or a string of characters.

Valid Example:


Invalid Example:

$_1pay // underscore must be followed by a letter
$1strname // Must begin with a letter or underscore
$_var-temp //contains non alphanumeric character(-)

Leave a Reply