PHP variables

A variable is a memory location to store a value.In PHP the value may be a string,number,flot,array even an object of a class etc. A variable begins with the $ sign

Rules for declare PHP variables:

  • A variable begins with the $ sign,followed by its name
  • A variable name must start with a letter or _ charactor
  • A variable name can only contain letters , number and _ charactor (A-z,0-9, and _)
  • Variable names are case sensitive $y not equal $Y

System allocated a space for a variable only when you assign a value for it

<?$txt="Hello world!";
$x=5;?> .


A php script can be write anywere in the file, A php script starts with <?php and end with ?>
example: <?php echo “Hello world”; ?>
This script print “Hello world” in your browser as output. The echo is a function used to print a value in the out put htmlEvery code line in PHP must end with a semicolon. The semicolon is a separator between the instructions from another.If you forgot to put a semicolon,php compiler will return an error (common mistakes in programming)

In PHP, there are two basic statements to print anything in the web browser: echo and print.

Leave a Reply

Your email address will not be published. Required fields are marked *