PHP Variable & Rules for PHP variables

You are currently viewing PHP Variable & Rules for PHP variables

PHP Variable & Rules for PHP variables

PHP Variable :- A PHP variable is a symbol that can store a value of different types, such as numbers, strings, arrays, objects, etc. A PHP variable can be used to perform calculations, manipulate data, or display information on a web page.

Creating (Declaring) PHP Variables-:

In PHP, a variable starts with the $ sign, followed by the name of the variable:

				
					<?php
$name= “Vishal Uttam”;
$age=26;
echo $name;
echo $age;
?>

				
			

After the execution of the statements above, the variable $name hold the value Vishal Uttam and the variable $age will hold the value 26.

When we assign a text value to a variable, we have to put quotes around the value.

Rules for PHP variables

A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).

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

Leave a Reply