The <
and >
comparison operators in PHP will compare the first character of your string, then compare other characters that follows in the strings.
Therefore, your first expression ai (first string) and i (second string) a is the first character in the string compared with i as the first character in the second string with >
will return false
, and subsequently the second statement will return true
due to the same reason.
However, if you really need to compare two longer string values with many characters, you may try using the substr_compare method:
substr_compare("abcde", "bc", 1, 2);
in this sample, you have your two strings to be compared, 1 is the offset start position, and 2 represents how many characters you want to compare to the right of those strings. -1 will means the offset start from the end of the first string. e.g. do something like this:
substr_compare("string1", "string2", 0, length);
also, consider using strcmp() also i.e. strcmp("string1", "string2", length)
where length is number of character you want to compare from the two strings.