Practise with variables

Variables are like storage areas to hold things like numbers and text. You can save values in a variable and do something with them. In this section, you’ll get some practice using variables:

<?PHP

$first_string = “This is my first string”;

print (“This is my first string”);

print($first_string);

?>

 

We’ve set up a variable called $first_string. After the equals sign, the text “This is my first string” has been added. The line is then ended with a semi-colon.

When you’ve finished typing above code, save this page as practice.php. Then Run the script. Remember: when you’re saving your work, save it to the WWW folder. To run the page, start your browser up and type this in the address bar:

http://127.0.0.1/variables.php

Or this:

http://localhost/variables.php

 

Concatenate with variables

You can join together two variables, and whatever is in your variable. The full stop (period or dot, to some) is used for this. Below I have explained about concatenate variables values:

<?PHP

$first_string = “This is my first string”;

$second_string=”This is my second string”;

print($first_string.$second_string);

?>

So now we have two variables. Both variables are holding our direct text. When we’re printing the contents of both variables, a full stop is used to separate the two. Try out the above script, and see what happens.