Page 61 - 2617_JSSPS_C-7
P. 61

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.





                                                                                                            PHP     59
   56   57   58   59   60   61   62   63   64   65   66