ch-4 variable in php


Variable in php
Unlike C, php does not need data type before declare variable name. In php we can directly declare and define variable name.
For example:
<?php
$a=10;
$b=20;
$c=$a+$b;
echo $c;
?>
Output:30
If you want to write string along with this output, So you can try below code
<?php
$a=10;
$b=20;
$c=$a+$b;
echo "answer is  $c";
?>
Output:
answer is  30
see above third output statement which enclosed within double quotes ("answer is  $c";) .
here, in place of  double quotes if you use single quotes like (‘answer is  $c’;) it will print  (answer is  $c).
for ex.
<?php
$a=10;
$b=20;
$c=$a+$b;
echo ‘answer is  $c’;
?>
Output:
answer is  $c

You can also store one variable value In another variable , and this process simply called variable variables.
<?php
$name="Gita Devi";
$$name=$name;
echo $$name;

$$$name=$$name;
echo $$$name;
?>
 Output:
Gita DeviGita Devi




Comments

Popular posts from this blog

Function