The comparision operators < <= > >=
can be applied for strings as well. So why do we need special function for string comparision: strcmp
?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- how to split a list into a given number of sub-lis
- Can php detect if javascript is on or not?
Because there are several variations:
Depending on the function, the answer to these questions vary:
strcmp
vsstrcasecmp
,strnatcmp
vsstrnatcasecmp
)strcoll
does)strcoll
is affected bysetlocale
)Additionaly, the comparison operators also give
true
orfalse
.strcmp
gives an integer so it can encode simultaneously whether there's identity (return 0) or, if it not, which is is bigger (depending on whether the value is positive or negative).Although there are no overloads in PHP for strcmp, strcmp results in 3 different values -1 for less than, 0 for equals and +1 for greater than the compared string. With
< = <= > >=
you will have (sometimes) to do multiple checks one after another.