Variable in PHP

Advertisements

PHP First Code Constant in PHP

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)

PHP First Code Constant in PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements