0
Can the equal operator be used for letters
def == def
3 Respuestas
+ 1
Yes. It's called String comparison.
"abc" == "abc" -> true
"abc" != "ABC" -> true
Trying to explain how it works:
The strings are created by character sequences (array of characters). Each character is actually a number pointing to a position of that character in the ASCII table.
Example of character comparison:
'A' == 'a' is actually 65 == 97 -> false.
So, how the string "abc" is compared to the "ABC" string?
As maybe you know, the Arrays contains elements (such as numbers, letters and etc) and each element is at specific index.
"abc" = [65, 66, 67]
"ABC" = [97, 98, 99]
index 0 1 2
So, behind the scene, it compare elements of both arrays at index 0, then 1, then 2 and so on, while the result is true. In my example it should stop at first, because:
65 == 97 -> false (so "abc" is not equal to "ABC").
0
thnx
0
Comparison operators are used inside conditional statements, and evaluate to either TRUE or FALSE.
Yes it can be use for strings. not just for true and false but you can also use an if statement and concatenate it with another string, like the integers (numbers) and echo it out. check the example below. the dot (.) sign in the middle is use to add a string together. like-> echo $can .' Posible';
<?php
$can = 'def';
if($can == 'def')
echo $can .' Posible';
}
?>