PHP TUTORIAL

Variable in PHP



In the previous chapter we learned about variable used in Math. We can also assign strings to variable. Variable and assignemnts statements ate two most important contructs in PHP ( as in other languages).

Let us take a look at another example.
<?php
$length = 10;
$width = 5;
$area = $length * $width ;
$header = "Area of rectangle is : ";
echo $header; 
echo $area;
?>

We have assigned a string to the variable $header and used it to print a line using the echo statement. We could use a mix of the echo statement to print some nice looking html. For example run the followig code
 
<?php
$length = 10;
$width = 5;
$area = $length * $width ;
$header1 = "My second program on referencedesigner.com";
$header2 = "Area of rectangle is : ";
echo  $header1; 
echo  "<br />"; 
echo $header2; 
echo $area;
?>
 

Exercize



It helps if your understanding, if you do some simple exercizes. Here are these

1. Write a php code that will print an h1 header saying Area of a Circle with radius 10. The value of the radius of the circle assigned initially to 10. Then print the area of the circle ( with value of pi = 3.14).

2. Write php code that will print two lines in the above. First it will print the radius of the circle and then it will prints its area in the second line.