Comparing strings in PHP can be achieved by comparing the size of two strings in two ways: Using operators to compare and using functions to compare the size of two strings using operators: when comparing two strings in PHP, the easiest way is to use the double equal sign operator (). Use a function to compare the size of a string: in PHP, extract
Comparing strings in PHP can be achieved by comparing the size of two strings in two ways: using the = Operator to compare and using a function to compare the size of two strings using the = Operator: when comparing two strings in PHP, the easiest way is to use the equal sign operator (= ). Use a function to compare the size of a string: in PHP, extract
Comparison string
In PHP, comparing the size of two strings can be achieved in two ways: using the "=" operator to compare and using functions
Use the "=" operator to compare the size of two strings: when comparing two strings in PHP, the easiest way is to use the equal sign operator (= ).
Use the function to compare the string size: The strcmp () function provided in PHP can more accurately compare the size of the two strings. The syntax format is as follows: int strcmp (string $ str1, string $ str2) the parameters involved in the preceding syntax are described as follows: str1 specifies the string 1 to be compared and str2 specifies the string 2 to be compared. The strcmp signature is used to ensure that the two strings match completely and return the comparison result in the form of an integer. The return values of this function include the following three types. 0: The two strings are equal. When the value is less than 0, the first string is smaller than the subsequent string. If the return value is greater than zero, it indicates that, the preceding string is greater than the following string.
In addition to the strcmp () function, PHP also provides some similar comparison functions. For example, the strncmp () function can select the length (number of characters) of the string to be compared ), the syntax format is as follows: int strcmp (string $ str1, string $ str2, int $ len) the preceding parameter description str1: Specifies the first string to be compared, str2: specify the second string to be compared len: specify the number of characters each string uses for comparison.
When comparing strings, you can use strcasemp () and strncasemp () functions to ignore case sensitivity, these two functions are used exactly the same as the case-sensitive functions. The syntax formats of strcasecmp () and strncasecmp () functions are as follows:
Int strcasecmp (string $ str1, string $ str2)
Int strncasecmp (string $ str1, string $ str2, int $ len)