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; ?...
<?php function add($a,$b) { echo $a+$b; } add(2,3); ?> Outrput:5 <?php function add($a,$b) { return $a+$b."<br>"; } $a =add(4,5); echo $a; ?> Output:9 Variable Variables: In function , here we can also use variable variables process. Where we can assign function name in another variable. For example:- <?php function add($a,$b) { return $a+$b."<br>"; } $fun='add'; echo $fun(5,6); ?> Output:11 Here ‘add’ function name is assign in ‘$func’.
Comments
Post a Comment