Ternary operator is simply short form of if/else statement. Ternary operator is also known as SHORTHAND operator.
The logic of using the Ternary operator is " (condition) ? true statement : false statement "
Example :-
Double equal to (==) and triple equal to (===) both are use as compression operator in Php. But there is big difference between double equal to (==) compression operator and triple equal to (===) compression operator.
Double equal to (==) compression operator can only compare the value but triple equal to (===) compression operator compare the value as well as data type of the value. This will be completely clear while seeing the below example.
Example :-
Comparing two value using double equal to compression operator
Output of the above code
The above example clearly shows that the variable 'b' contain string value but the output shows both the values are same.
Now the same example is performed using the triple equal to compression operator
Output of the above code
While using the triple equal to compression operator the output shows both the values are not same as it compare the value as well as data type of the value.
An operator is a symbol that represent a specific action.Operators are used to perform operations on variables and values.
Assignment operator
Assignment Operator is used to assign value to any variable. We can assign the value directly to the variable or after performing any operation we can assign value to variable. To assign value to variable '=' sign is used.
Example
Don't get confused while using single equal to( = ) sign or double equal to ( == ) sign. Single equal to sign is used for assignment but double equal to sign is used for compression
An operator is a symbol that represent a specific action.Operators are used to perform operations on variables and values.
Logical Operators
There are three types of logical operators a) Logical AND operator b) Logical OR operator c) Logical NOT operator
a) Logical AND operator
In logical AND operator we check more than one conditional and all the condition must get true if we want to execute the statement. The best example of logical AND operator login system. In php double am-percent ( && ) sign is used as logical AND operator.
Example
Output of the above code
b) Logical OR operator
In logical OR operator if any condition get true then it will execute the statement. In Php double pipe ( || ) sign is used as logical OR operator.
Example
Unlike AND operator we don't need to get both the condition true. If any one of these get true it will execute the if block. Else block are only executed if both the condition are get false.
The output of the above code c) Logical NOT operator
In Php exclamation mark ( ! ) is used as logical OR operator.
Example
An operator is a symbol that represent a specific action.Operators are used to perform operations on variables and values.
Comparison Operator
Comparison Operator is used to compare between two and more variables and values . In Php double equal to ( == ) sign is used used as compression operator.
An operator is a symbol that represent a specific action.Operators are used to perform operations on variables and values.
Types of operators in php 1.) Arithmetic Operator 2.) Comparison Operator 3.) Logical Operator 4.) Assignment operator 5.) Conditional Operator
1. Arithmetic Operator
In Arithmetic Operators we perform + Addition - Subtraction * Multiplication / Division % Modulus (to calculate reminder)
Example
2. Comparison Operator
Comparison Operator is used to compare between two and more variables and values . In Php double equal to (== ) sign is used used as compression operator.
Example
3.) Logical Operators
In Logical Operator we perform a) Logical AND operator b) Logical OR operator c) Logical NOT operator
a) Logical AND operator
In logical AND operator we check more than one conditional and all the condition must get true if we want to execute the statement. The best example of logical AND operator login system. In php double am-percent ( && ) sign is used as logical AND operator.
Example
b) Logical OR operator
In logical OR operator if any condition get true then it will execute the statement. In Php double pipe ( || ) sign is used as logical OR operator.
Example
Unlike AND operator we don't need to get both the condition true. If any one of these get true it will execute the if block. Else block are only executed if both the condition are get false.
c) Logical NOT operator
In Php exclamation mark ( ! ) is used as logical OR operator.
Example
4. Assignment operator
Assignment Operator is used to assign value to any variable. We can assign the value directly to the variable or after performing any operation we can assign value to variable. To assign value to variable '=' sign is used.
Example
Don't get confused while using single equal to ( = ) sign or double equal to ( == ) sign. Single equal to sign is used for assignment but double equal to sign is used for compression
5.) Conditional Operator
Conditional operator contains < Less Than > Great Than <= Less Than Equal to >= Great Than Equal to
Example