Variable in PHP


Prev Tutorial Next Tutorial

Variable in PHP

Variable is an identifier which holds data or another one variable and whose value can be changed at the execution time of script. In PHP, a variable starts with the $ sign, followed by the name of the variable.

Syntax to declare variable in php

Syntax

$variablename=value;  

Example of variable in php

<?php

$str="Hello world!";
$a=5;
$b=10.5;
echo "String is: $str <br/>";  
echo "Integer is: $x <br/>";  
echo "Float is: $y <br/>";  

?>

Output

String is: Hello world!
Integer is: 5
Float is: 10.5 

Variable $str will hold the string value Hello world!, variable $x will hold the interger value 5 and variable $y will hold float value 10.5.

Rules to declare variable in PHP

  • 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 can't 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 ($str and $STR both are two different)

Prev Tutorial Next Tutorial

Advertisements
z
Download Projects

Advertisements

Download WhatsApp Status Video

Buy This Ad Space Only $50 per Month, Ad Size 300X250 Contact on: [email protected] WhatsApp no. 8882538826

Google Adsense Advertisements