Connect with us

PHP

PHP Operator

mm

Published

on

Operator could be given using term 4 + 7 is equal to 11. Here 4 and 7 are called operands and + is called operator.

PHP supports subsequent type of operators:-
• Arithmetic Operators
• Comparison Operators
• Logical (or Relational) Operators
• Assignment Operators
• Conditional (or ternary) Operators
Arithmetic Operators:-
These operators are used with numeric values to execute universal arithmetical operations, such as addition, subtraction etc.

Example:-

Operator Description Example
+ Adds two operands 5 + 1 will give 6
Subtracts second operand from the first 5 – 1 will give 4
* Multiply both operands 4 * 5 will give 20
/ Divide numerator by de-numerator 5 / 1 will give 5
% Modulus Operator and remainder of after an integer division 5% 1 will give 0
++ Increment operator, increases integer value by one 5++ will give 6
Decrement operator, decreases integer value by one 5– will give 4

Comparison Operators:-
These operators are used for comparison.

Example:-

Operator Description Example
== Checks if the value of two operands is equal or not, if yes then condition becomes true. (5 == 1) is not true.
!= Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. (5 != 1) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (1> 5) is not true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (1 < 5) 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. (1 >= 5) 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. (1 <= 1) is true.
Also Read :   How to skip or remove shipping and payment steps from checkout in magento

Logical Operators:-
These operators are used for logical functions.

Example:-

Operator Description Example
and Called Logical AND operator. If both the operands are true then condition becomes true. (K and Z) is true.
or Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. (K or Z) is true.
&& Called Logical AND operator. If both the operands are non zero then condition becomes true. (K && Z) is true.
|| Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. (K || Z) is true.
! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. !(K && Z) is false.

Assignment Operators:-
There are subsequent assignment operators.

Example:-

Operator Description Example
= Simple assignment operator, Assigns values from right side operands to left side operand K = L + M will assign value of L + M into K
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand K += L is equivalent to K = K + L
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand K-= L is equivalent to K = K – L
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand K*= L is equivalent to K = K * L
/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand K/= L is equivalent to K = K / L
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand K %= L is equivalent to K = K % L
Also Read :   How to Add Custom Header Links in Magento 2

Conditional Operator:-
This operator evaluates an expression for a true or false value and then executes one of the two given declarations depending upon the result of the assessment.

Example:-

Operator Description Example
? : Conditional Expression If Condition is true ? Then value K : Otherwise value M

 

Hi, Thank you for reading my article. I am Victor, a professional blogger from Jaipur, India.I started webetutorial for blogging & sharing solution for developer questions, and now it’s empowering globally by helping them to make money.I am writing about starting & managing a blogs, WordPress, Magento, Social Media, SEO, Marketing, making money online, Investment, Finance, Gadgets, Fitness and more.

Continue Reading
Advertisement
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

nineteen − 18 =

Blog

PHP Magic Methods

mm

Published

on

  1. __get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically.
  2. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is set or not.
  3. __unset() – Similarly, when we call PHP unset() function on such dynamically created properties, this magic method will automatically be invoked.
  4. __call()/__callStatic() – These two magic methods are dedicated for accessing dynamically created but invisible methods on PHP method overloading.
  5. __sleep() – This will be invoked on calling PHP serialize() function.
  6. __wakeup() – It will do the reverse work to restore objects properties and resources.
  7. __toString() – This method is expected return a string value while using class instances with PHP printing statements.
  8. __invoke()-This method defined in a class will be called when we make a function call with the name of that class instance.
  9. __set_static()-This is a static method invoked while exporting objects property array and expects such array variable as its argument.
  10. __clone()-This function is used while PHP Object Cloning.
  11. __construct()/__destruct()

Also Read :   Product Attachment for Magento 2
Continue Reading

Subscribe to our newsletter

Enter your email address to subscribe to blog and receive notifications of new articles by email.
100% Privacy. No spam guaranteed

Trending