Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 168 - 2633 Trackpad Pro V5.1 Class 7
P. 168

    function            global              goto                if                  implements
                       include             instanceof          insteadof           interface           isset

                       list                namespace           new                 or                  print
                       private             protected           public              require             return

                       static              switch              throw               try                 use
                       var                 while               xor                 yield

                      VARIABLES IN PHP

                      A variable is a memory location that is used to store a value. When a variable is created, some
                      space is allocated in memory for it. This memory space is referred by the name that we give to an

                      identifier. A variable name must start with a $ (dollar) sign. For example,

                      <?php
                      $age = 12;
                      $name = "Divya";
                      $address = "12A, Stree No-4, Govindpuri";
                      $section = 'C';

                      ?>
                      Here 12, "Divya", "12A, Stree No-4, Govindpuri" and 'C' are the values assigned to variables
                      named age, name, address and section respectively. The = (equal) operator is used to assign
                      a value to a variable. Let us create a web page to show the use of variables. Type the following

                      code in notepad:

                      <HTML>
                      <HEAD> <TITLE> Using Variables </TITLE> </HEAD>

                      <BODY>
                      <?php
                      $name = "Divya";

                      echo "Welcome ", $name;
                      ?>
                      </BODY>
                      </HTML>
                      Note that the comma is used to append the variable value with the text “Welcome”. Save the file

                      with Using Variables.php name. Now execute the script, as shown:

                      166
                      OPERATORS IN PHP
                            Premium Edition-VII

| 163 164 165 166 167 168 169 170 171 172 173 |