PHP

Variables

PHP / Variables

Variables

Variables

Variables are containers used to store information in a program.

A variable can have a short name like $x or $y, or a more meaningful name like $age, $carName, $totalVolume to make the code easy to understand.

In PHP, a variable is used to store data values such as text, numbers, or other information that can be used later in the program.

All PHP variables start with a dollar sign ($) followed by the variable name.

Rules for PHP Variables

  • A variable must start 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 alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($age and $AGE are two different variables)


 

Example

$x = 5;
$y = "John";

echo $x;
echo "\n";
echo $y;
?>

Technology
PHP
want to connect with us ?
Contact Us