Variables in PHP | How to use variables in php

Variables in PHP

Variables in PHP


So Hi guys today we are going to learn variables in PHP so I hope you are also excited like us so let's begin.

What is Variable in PHP

Variables are containers for storing information and variable starts with $ and variables are case sensitive.
EX - $name = "Rahul";

Rules For creating variables

  • Variables start with a $ Sign
  • Cannot start with a number
  • Must start with a letter or an underscore character
  • Can Only contain alphanumeric characters and underscore 
  • Variables in PHP are Case sensitive. Ex $rahul and $Rahul are different.

How to use variables in PHP

So here is an example of using variables in PHP. 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html language="en">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
        <title><?php echo"My 1st PHP Title" ?></title>
    </head>
    <body>

        <h1><?php echo"My PHP Variables"; ?></h1>
        
        <?php
        
        //PHP variables 
        $name= "Rahul";
        $percent= 90.14;
        
       echo"$name is a good boy and his 12th Percent is $percent</br>";
       
       //Just for space
       echo"<br>";
       
       //Variables in PHP are Case sensitive
       $Name= "Rohit";
       
       echo"$name and $Name is Best Friends.";
       
        ?>
        
    </body>
</html>

Post a Comment

0 Comments