Tuesday, 28 March 2017

Working with Variables in PHP

 In PHP you can do some addition with the PHP addition operator , +, to add numbers together like this:
<html>
<head>
<title>Variable in PHP
</title>
</head>
<body>
<h1>
The Answer:
</h1> <br>
<?php
echo "Answer" ,1+4+6,".";
?>
</body>
</html>
We run first time this, it display the message
The Answer:
Answer:11

Another way of variable representation in PHP. In PHP variable name begin with a $ sign followed by a name and that name must start with a letter or an underscore not a number. foe example to store the number of users in p you might have a variable named $p; the number of users in q and r might be in variable $q and $r. you could place data in those variable at run time and add those three data items together also at run time.

<html>
<head>
<title>Variable in PHP
</title>
</head>
<body>
<h1>
The Answer:
</h1> <br>
<?php
echo "Answer" ,$p+$q+$r,".";
?>
</body>
</html>
at run time the value inside each variable is substituted for that variable so if $p=1, $q=4, and $r=6, the preceding line of PHP code would look like this to PHP:
<?php
echo"Answer:",1+4+6,".";
?>
and so you get "Answer:11"

No comments:

Post a Comment