हिंदी
तमिलनाडु बोर्ड ऑफ सेकेंडरी एज्युकेशनएचएससी विज्ञान कक्षा १२

Explain operators in PHP with examples. - Computer Applications

Advertisements
Advertisements

प्रश्न

Explain operators in PHP with examples.

दीर्घउत्तर

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 4: Introduction to Hypertext Pre-Processor - Evaluation - PART – IV [पृष्ठ ९७]

APPEARS IN

सामाचीर कलवी Computer Applications [English] Class 12 TN Board
अध्याय 4 Introduction to Hypertext Pre-Processor
Evaluation - PART – IV | Q 5. | पृष्ठ ९७
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×