In this lesson we will be discussing operators in php. Operators are used to perform certain operations on some variables/operands. Example of operators includes mathematical operators such as “+”, “-”,”=” and etc.
Operators are divided into four categories:
• Arithmetic Operators
• Assignment Operators
• Comparison Operators
• Logical Operators
In this lesson I will be discussing Arithmetic operators only, the rest of the operators will be discussed in the upcoming lectures.
Arithmatic Operators
Arithmetic operators are used to perform arithmetic operations such as addition, subtraction and etc.
Addition Operator (+)
< ?php $a=5; $b=6; echo $a+$b; // outputs 11 ?>
Subtraction Operator (-)
< ?php $a=10; $b=6; echo $a-$b; // outputs 4 ?>
Multiplication Operator (*)
< ?php $a=5; $b=6; echo $a*$b; // outputs 30 ?>
Division Operator (/)
< ?php $a=30; $b=6; echo $a/$b; // outputs 5 ?>
Modulus Operator (%)
Modulus operator returns the remainder of division.
< ?php $a=5; $b=2; echo $a%$b; // outputs 1 ?>
Increment Operator (++)
< ?php $a=5; $a++; echo $a; // outputs 6 ?>
Decrement Operator (--)
< ?php $a=5; $a—; echo $a; // outputs 4 ?>
Well thats all for the fourth lesson, I hope u guys are enjoying my lessons and learning some php and if you have any query then feel free to comment and ask, I will try my level best to answer your question.
Previous Lesson --- Next Lesson
No comments:
Post a Comment