Variable & its Scope in PHP

2 3

In the last tutorial I have guided you through the Installation Procedure of XAMPP, Now we will discuss variable and its scope. But before that, if you have not seen the previous posts Introduction to PHP & How to install PHP.

What is Variable?

In mathematical terminology, a variable is an entity that can vary or have different values in a different state. In the contrast of variable with the mathematical world, a variable is an entity that could change and store some identifiers and constants. So it is more like a container.

Creating / Declaring PHP Variables:

If you are from C or Java background. Whenever you want to use a variable you need to declare it first then only you can use it to store value, but, Since PHP is an interpreted language, so like other interpreted language, the Variable doesn’t need to declare first. Doesn’t it make sense to call variable a container, as in real world, a container can store anything that is capable to be fit inside it, similarly a PHP variable can store anything. A variable in PHP starts with the $ symbol. For Example:

$name=”Tekraze “;
echo “These are my Variable: “;
echo $name, $Roll_no,” “, $fees;

OUTPUT: These are my Variable: Tekraze, 27, 500.80

As shown in the above snippet, the three variable created above $name, $Roll_no, $fees will hold the value Tekraze, 27, and 500.80 correspondingly.

Content Protection by
  1. Saurabh says

    Thanks for sharing the informative blog post. I have found here lots of interesting information for my knowledge I need. All the details you provide to us, it was very helpful and useful. Thanks for sharing this amazing post. I appreciate your efforts.
    Check out some latest Shopping Apps

    1. Balvinder Singh says

      Thanks Saurabh, share with others and keep visiting

Leave A Reply

Your email address will not be published.

CommentLuv badge

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More