Search

PHP Variables

The Variables are "containers" for storing any information .

Creating And (Declaring) PHP Variables

In PHP, a variable is declared using a dollar $ sign followed by the variable name. Here, some important points to know about variables

<?php
$txt = "Hello Stack !";
$x = 5;
$y = 3.5;
?>

After the execution of the declare variable above, the variable $txt will hold the value Hello Stack !, the variable $x will hold the value 5, and the variable $y will hold the value 3.5.

Rules of PHP variables:

  1. The php variable starts with the $ sign, followed by the name of the variable
  2. A variable name must start with a letter or the underscore character
  3. A variable name cannot start with a number
  4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  5. A Variable names are case-sensitive ($age and $AGE are two different variables)

php automatically judge what type of store value in a variable like string or number or floating point number

 

Stack Overlode is optimized Tutorials and examples for learning and training. Examples might be simplified to improve reading and learning and understand. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using Stack Overlode, you agree to have read and accepted our terms of use, cookie and privacy policy.