String and numeric comparison operators
String Operator | Comparison | Equivalent numeric operator |
lt | Less Then | < |
gt | Greater than | > |
eq | Equal to | == |
le | Less than or equal to | <= |
ge | Greater than or equal to | >= |
ne | Not equal to | != |
cmp | Compare , returning 1 (greater then), 0 (equal) , -1 ( less than) | <=> |
Single-Quoted strings vs Double-Quoted String:
1) double-quoted strings is that scalar variables are replaced by their values in double-quoted strings but not in single quoted string.
e.g.
$string = " a string";
$text = " This is $string"; # become " This is a string"
$text = 'This is $string'; # remains 'This is $string'
2) The\ character has not special meanings in single-quoted strings:
e.g.
$text ='This is a string.\n' # remains This is a string. \n
Conditional Operator:
$result =$var ==0 ? 14: 7;
is identical to the following:
if($var==0) {
$result = 14;
} else{
$result = 7;
}
Examples of assignment operators:
$a +=1; # $a= $a +1;
$a %= 2; # $a = $a%2 ; reminder and assignment
$a ^=2; # $a =$a ^2; bitwise XOR and assignment
++$a ; # autoincrement, pre-increment operation, add 1 before doing anything
$a++; # post-increment operation
No comments:
Post a Comment