: This article mainly introduces the usage and analysis of strcmp and strcasecmp function strings in PHP. if you are interested in the PHP Tutorial, refer to it. This document describes how to compare strcmp () and strcasecmp () functions in PHP. We will share this with you for your reference. The details are as follows:
1. the strcmp () function in PHP is used to compare two strings (case sensitive). its definition is as follows:
Strcmp (string1, string2)
Parameter description:
String1 is required. Specifies the first string to be compared.
String2 is required. Specifies the second string to be compared.
PS: The strcmp () function is similar to the strncmp () function. The difference is that strncmp () can specify the number of characters that each string uses for comparison.
2. the strcasecmp () function in PHP compares two strings (case-insensitive). its definition is as follows:
Strcasecmp (string1, string2)
Parameter description:
String1 is required. Specifies the first string to be compared.
String2 is required. Specifies the second string to be compared.
PS: The strcasecmp () function is similar to the strncasecmp () function. The difference is that strncasecmp () can specify the number of characters that each string uses for comparison.
Sample code:
<? Php $ str1 = ""; $ str2 = ""; $ str3 = "www.jb51.net"; $ str4 = "WWW. JB51.NET "; echo strcmp ($ str1, $ str2); // two strings are equal to echo"
"; Echo strcmp ($ str3, $ str4); // note that this function is case sensitive echo"
"; Echo strcasecmp ($ str3, $ str4); // is this function case insensitive?>
The running result is as follows:
010
Supplement: Questions about return values
Comparison between string1 and string2:
If the two strings are equal, the return value is 0.
If string1 is less than string2, the return value is less than 0.
If string1 is greater than string2, the return value is greater than 0.
I hope this article will help you with PHP programming.
The above introduces the comparative usage analysis of strcmp and strcasecmp function strings in PHP, including some content, and hope to help those who are interested in PHP tutorials.