Monday, July 2, 2018

Variables

Creating (Declaring) PHP Variables

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

Ex:

$name;

$numeber;

=======

<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>

After the execution of the statements above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 10.5.

======


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)
Remember that PHP variable names are case-sensitive!


Ex:

$name = 'Edwin'; //string type variable must in quotes or double quotes
$name = "Edwin";
$number = 100; // not required quotes for number type
$Number_List = 10.5;


//$nam-ber = 'Edwin'; // error came
//$0name = 'Edwin'; // A variable name cannot start with a number

$NUMBER = 100 // case sencitive

----------------


we can siisgn html tags & images i.e

Ex: 

$name = "<h1>Hello</h1>"

echo $name;


---------------