Learn PHP : PHP variables

Considering you know the installation and configuration of WAMP or XAMPP, and you have setup your PHP on your local machine.

This is guidance for candidates who really want to learn PHP.

So, Start.
Before you continue you should have a basic understanding of the following:
  • HTML
  • CSS
  • JavaScript

We are starting with variable.

What is PHP variable?
Answer: Variables are "containers" for storing information.

In PHP, a variable starts with the $ sign, followed by the name of the variable:


$txt = "Hello world!";
$x = 10;
$y = 20;
In above example, $txt is variable, which stores value "Hello word!". 
$x and $y also variables and they stores value as 10 and 20 respectively.

Note that when you are going to store string or text in variable do include that string in single quote or double.

If you want to store integer value in variable don't use quotes.

Using that variables as for example:

 echo $txt; 
echo "<br/>";
echo $x;
echo "<br/>";
echo $y;
echo "<br/>";

echo $z;


Hello word!

echo is construct we use to print in PHP. There is <br/> tag used with this echo that is for print new line.
$z stores sum of $x and $y.

In PHP we don't specify data type of variable, it automatically recognize.

That's it for this post, will post something important in next post, stay connected.

No comments:

Post a Comment

We are here to listen you, Comment your valueable opinion...!!!