Course Content
Introduction
PHP is an object-oriented scripting programming language that allows web developers to create dynamic and interactive web pages. PHP stands for Hypertext Preprocessor (PHP).
0/14
Control Statement
A control statement is a statement that determines whether other statements will be executed.
0/7
    About Lesson

    The operator is a symbol that is used to execute operations on operands.

    PHP divides the operators into the following groups:

    • Arithmetic Operators
    • Assignment Operators
    • Bitwise Operators
    • Comparison Operators
    • Incrementing/Decrementing Operators
    • Logical Operators
    • String Operators
    • Type Operators
    • Error Control Operators

     

    Arithmetic Operators

    Arithmetic operators are used to perform common arithmetic operations such as addition, subtraction, etc. with numeric values.

    OperatorNameExampleExplanation
    +Addition$a + $bSum of $a and $b
    Subtraction$a – $bA difference of $a and $b
    *Multiplication$a * $bProduct of $a and $b
    /Division$a / $bQuotient of $a and $b
    %Modulus$a % $bThe remainder of $a divided by $b
    **Exponentiation$a ** $bResult of raising $a to the $b’th power

     

    Assignment Operators

    OperatorNameExampleExplanation
    =Assign$a = $bThe value of the right operand is assigned to the left operand.
    +=Add then Assign$a += $bAddition same as $a = $a + $b
    -=Subtract then Assign$a -= $bSubtraction same as $a = $a – $b
    *=Multiply then Assign$a *= $bMultiplication same as $a = $a * $b
    /=Divide then Assign (quotient)$a /= $bFind quotient same as $a = $a / $b
    %=Divide then Assign (remainder)$a %= $bFind remainder same as $a = $a % $b

     

    Bitwise Operators

    The bitwise operators are used to perform bit-level operations on variables.

    OperatorNameExampleExplanation
    &And$a & $bBits that are 1 in both $a and $b are set to 1, otherwise 0.
    |Or (Inclusive or)$a | $bBits that are 1 in either $a or $b are set to 1
    ^Xor (Exclusive or)$a ^ $bBits that are 1 in either $a or $b are set to 0.
    ~Not~$aBits that are 1 set to 0 and bits that are 0 are set to 1

     

    Comparison Operators

    Comparison operators are used to comparing two values, such as number or string.

    OperatorNameExampleExplanation
    ==Equal$a == $bReturn TRUE if $a is equal to $b
    ===Identical$a === $bReturn TRUE if $a is equal to $b, and they are of the same data type
    !==Not identical$a !== $bReturn TRUE if $a is not equal to $b, and they are not of the same data type
    !=Not equal$a != $bReturn TRUE if $a is not equal to $b
    <>Not equal$a <> $bReturn TRUE if $a is not equal to $b
    <Less than$a < $bReturn TRUE if $a is less than $b
    >Greater than$a > $bReturn TRUE if $a is greater than $b
    <=Less than or equal to$a <= $bReturn TRUE if $a is less than or equal $b
    >=Greater than or equal to$a >= $bReturn TRUE if $a is greater than or equal $b
    <=>Spaceship$a <=>$bReturn -1 if $a is less than $b
    Return 0 if $a is equal $b
    Return 1 if $a is greater than $b

     

    Incrementing/Decrementing Operators

    The increment and decrement operators are used to increase and decrease the value of a variable.

    OperatorNameExampleExplanation
    ++Increment++$aIncrement the value of $a by one, then return $a
    $a++Return $a, then increment the value of $a by one
    decrement–$aDecrement the value of $a by one, then return $a
    $a–Return $a, then decrement the value of $a by one

     

    Logical Operators

    The logical operators are used to perform bit-level operations on variables.

    OperatorNameExampleExplanation
    andAnd$a and $bReturn TRUE if both $a and $b are true
    orOr$a or $bReturn TRUE if either $a or $b is true
    xorXor$a xor $bReturn TRUE if either $ or $b is true but not both
    !Not! $aReturn TRUE if $a is not true
    &&And$a && $bReturn TRUE if either $a and $b are true
    ||Or$a || $bReturn TRUE if either $a or $b is true

     

    String Operators

    The string operators are used to operate on strings.

    OperatorNameExampleExplanation
    .Concatenation$a . $bConcatenate both $a and $b
    .=Concatenation and Assignment$a .= $bFirst concatenate $a and $b, then assign the concatenated string to $a, e.g. $a = $a . $b

     

    Error Control Operators

    PHP has one error control operator, i.e., at (@) symbol. Whenever it is used with an expression, any error message will be ignored that might be generated by that expression.

    OperatorNameExampleExplanation
    @at@file (‘non_existent_file’)Intentional file error