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:

Example

<?php
$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:

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

$z=$x$y;
echo $z;

 ?>

Output:
Hello word!
10
20
30

Explaination:
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.

1 comment:

  1. I have read your blog it’s very attractive and impressive. I like it your blog.
    Click for this

    ReplyDelete

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