English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

Explain operators in PHP with examples.

Advertisements
Advertisements

Question

Explain operators in PHP with examples.

Long Answer
Advertisements

Solution

The operator is a symbol which is used to perform mathematical and logical operations in the programming languages. Different types of operators in PHP are:

  • Arithmetic operators:
    The arithmetic operators in PHP perform general arithmetical operations, such as addition, subtraction, multiplication and division etc.
Symbol Operator Name Purpose
+ Addition This operator performs the process of adding numbers
- Subtraction This operator performs the process of subtracting numbers
* Multiplication This operator performs the process of multiplying numbers
/ Division This operator performs the process of dividing numbers
% Modulus This operator performs the process of finding remainder in division operation of two numbers
  • Assignment Operators:
    Assignment operators are performed with numeric values to store a value to a variable. The default assignment operator is “=”. This operator sets the left side operant value of expression to right side variable.
Assignment Similar to Description
x = y x = y This operator sets the left side operant value of
expression to right side variable
x += y x = x + y Addition
x -= y x = x - y Subtraction
x*= y x = x*y Multiplication
x/= y x=x/y Division
x %=y x = x % y Modulus
  • Comparison Operators:
    Comparison operators perform an action to compare two values. These values may contain integer or string data types (Number or Strings).
Symbol Operator Name Symbol Operator Name
== Equal > Greater than
=== Identical < Less than
!= Not equal >= Greater than or equal to
<> Not equal <= Less than or equal to
!== Not identical    
  • Increment and Decrement Operators:
    Increment and decrement operators are used to perform the task of increasing or decreasing variable’s value. This operator is mostly used during iterations in the program logics.
Operator Name Description
++$x Pre-increment Increments $x value by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one
  • Logical Operators:
    Logical Operators are used to combine conditional statements.
Symbol Operator Name Example Result
&& And $x && $y True if both $x and $y are true
Il Or $x Il $y True if either $x or Sy is true
! Not !$x True if $x is not true
xor Xor $x xor $y True if either $x or Sy is true, but not both
  • String Operators:
    Two operators are used to perform string related operations such as Concatenation and Concatenation assignment (Appends).
Operator Name Example Result
. Concatenation $textl . $ text2 Concatenation of $txt1 and $txt2
.= Concatenation assignment $textl = $ text2 Appends $txt2 to $txtl
shaalaa.com
Web Development Concept
  Is there an error in this question or solution?
Chapter 4: Introduction to Hypertext Pre-Processor - Evaluation - PART – IV [Page 97]

APPEARS IN

Samacheer Kalvi Computer Applications [English] Class 12 TN Board
Chapter 4 Introduction to Hypertext Pre-Processor
Evaluation - PART – IV | Q 5. | Page 97
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×