Basic HTML Version

|  | Table of Contents |  | View Full Version

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

    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.

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

                       <BODY>
                       <?php

                       $a = 10;
                                                                                 Use of + operator
                       $b = 5;
                                                                                              Use of - operator
                       echo "The sum of two numbers is ", $a+$b;
                       echo "<br>The difference of two numbers is ", $a-$b;

                       echo "<br>The product of two numbers is ", $a*$b;

                       ?>                                                                   Use of * operator
                       </BODY>
                       </HTML>

                        Note that the <br> tag is used to print the text in next line. We get the following output by
                       executing the preceding script:

                        Relational operators: These operators help to compare quantities and return Boolean value
                       'True' or 'False' as the output. Relational operators of PHP are ==, !=, >, <, >=, and <=. Let us create
                       a PHP script to use some of the relational operators.

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

                       <BODY>
                       <?php
                       $a = 10;

                       $b = 5;

                                                                                                     Techipedia (PHP)  167

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