PHP Operators- Tutorialpath

Hello to all of you, thanks for landing on the TutorialPath.com, which is “Your Path to Learn Everything” in an easy way and you can learn almost every sort of important elements about online things. As you land here, so we can assume, you are a newbie for PHP Operators language, so you don’t need to worry about it.

Welcome to all our readers on our website at www.tutorialpath.com. As you all know that here on our website we will provide you lots of information related to the latest and newly introduced technology which help you to get updated with the latest tech. Here you will get all the useful information which is required in this tech world. As you know technology is one of the trending part in this world. So, here again we came up with a latest and new tech information which is related to the process of creating Basic PHP Operators for Beginners. With the help of this article you will get to know the complete process of how to create Basic PHP Operators for Beginners in a step by step manner. So, simply have a look to this article and grab all the useful information which is going to be very helpful for you.

What is Operator?

Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator.

PHP Operator is a symbol i.e used to perform operations on operands.

PHP language supports following type of operators. for example:

In the above example, + is the binary + operator, 10 and 20 are operands and $num is variable.

  1. Arithmetic Operators
  2. Comparison Operators
  3. Logical (or Relational) Operators
  4. Assignment Operators

Arithmetic Operators

The arithmetic operators are used to perform common arithmetical operations, such as addition, subtraction, multiplication etc. Here’s a complete list of PHP’s arithmetic operators:

Operator Description Example Result
+ Addition $x  +  $y Sum of $x and $y
Subtraction $x  –  $y Difference of $x and $y.
* Multiplication $x  *  $y Product of $x and $y.
/ Division $x  /  $y Quotient of $x and $y
% Modulus $x  %  $y Remainder of $x divided by $y

Example:

output:

Comparison Operators

The comparison operators are used to compare two values in a Boolean fashion.

Examples

Operator                              Description Example
== Checks if the value of two operands are equal or not, if yes then condition becomes true. (A == B) is not true.
!= Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (A != B) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A > B) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.

 

Example:

output:

PHP Assignment Operators

The assignment operators are used to assign values to variables.

Operator Description Example Is The Same As
= Assign $x = $y $x = $y
+= Add and assign $x += $y $x = $x + $y
-= Subtract and assign $x -= $y $x = $x – $y
*= Multiply and assign $x *= $y $x = $x * $y
/= Divide and assign quotient $x /= $y $x = $x / $y
%= Divide and assign modulus $x %= $y $x = $x % $y

Example:

Output:

PHP Logical Operators

The logical operators are typically used to combine conditional statements.

Operator Name Example Result
and And $x And $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $$x or $y is true
! Not !$x True if $x is not true

 

Example:

Output:

Leave a Reply

Your email address will not be published.