Monday, 22 June 2015

What is variable and how to declare in php ?

Variables are "containers" for storing information.

<?php
$str = "Hello world!";
$x = 10;
$y = 15.5;
?>

NOTE : -

the variable $str will hold the value Hello world!
the variable $x will hold the value 10
and the variable $y will hold the value 15.5.




Rules for variable declaration:

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)

No comments:

Post a Comment