Page 130 - C_GPT _V4 _class_7
P. 130

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
              UsingVariables.php name. Now execute the script, as shown:














              OPERATORS IN PHP

              Operators are special symbols in PHP that are used to perform arithmetic or logical computation. The
              variables of values used with the variables are known as operands. The combination of operators and
              operands is called an expression. There are various types of operators, which are as follows:

                  Arithmetic operators:  These operators are used  to  do  basic  mathematical calculations.  The
                 arithmetic operators of PHP are +, -, *, /, and %. Let us create a PHP script to use some of the
                 arithmetic operators.





                        CodeGPT (Ver. 4.0)-VII
                128
   125   126   127   128   129   130   131   132   133   134   135