PHP variables

By | November 28, 2022

Variable is an image or name that represents a worth. Factors are utilized for putting away qualities, for example, numeric qualities, characters, character strings, or memory addresses with the goal that they can be utilized in any piece of the program.

How to declare variable in PHP (Naming convention of variable in PHP)

  1. Variables start with the $ sign followed by the name of the variables
  2. A variable name must start with a letter or the underscore character
  3. A variable name cannot start with a number
  4. A valuable name can only contain alpha numeric characters and underscores (A-z and _)
  5. Variable name are case sensitive ($age and $AGE are two different types of variables)
<?php
$txt = “Hello world!”;
$x = 2;
$y = 7;
?>

After the declaration of the statement above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 2 and the variable $y will hold the value 7