| Triple Equals in php |
This tutorial is for Triple Equals.
Let me justify you difference between Double Equal Operator and Triple Equal Operator:-
Single Equal Operator:-It is used for assigning values.
Double Equal Operator:-It is used for equality between variables and values.
Triple Equal Operator:-It is used for equality between variables and values and there datatype too.
Let me justify you difference between Double Equal Operator and Triple Equal Operator:-
Single Equal Operator:-It is used for assigning values.
Double Equal Operator:-It is used for equality between variables and values.
Triple Equal Operator:-It is used for equality between variables and values and there datatype too.
Code for comparison operators (Screenshot1):-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| <?php$num1 = '1';$num2 = 1;if ($num1==$num2) {echo 'Equal.';}else{echo'Not equal.';}?> |
Output (Screenshot2) :-
In this example we had two variables where num1 is string datatype and num2 is integer datatype.Here,in “Double Equals” we can compare the values of variables num1 and num2,but what if we want to compare datatypes of variable along with the comparisonof values.Let’s see an example:-
Code for Triple Equals Operators (Screenshot3):-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| <?php$num1 = '1';$num2 = 1;if ($num1===$num2) {echo 'Equal.';}else{echo'Not equal.';}?> |
Output (Screenshot4):-
In this example during comparison of datatype of the variable i.e. string and integer, it evaluates false and echo out “Not equal”.
Read More Extra Tutorials
No comments:
Post a Comment