PHP character comparison strcmp () function use method _php Tutorial

Source: Internet
Author: User
Tags strcmp
The use of the strcmp () function is to compare two strings, and if two strings are exactly equal we return 0, otherwise there will be various return values, this function is case-sensitive and can be referenced by friends who need it.

Return value Description after comparison

Returns 0 if str1 and str2 are equal.
If the str1 is less than str2 return <0 (but not necessarily-1, many of the internet is said to be-1, is not correct, the specific value of the actual situation depends on the size).
If STR1 is greater than str2, the >0 is returned (but not necessarily 1, depending on the actual value).

Cases

The code is as follows Copy Code

strcmp (Date (' y-m-d ', $user->last_time), date ("Y-m-d", Time ())) = = 0

If you do not distinguish between case

STRNCASECMP is used as part of a case-insensitive comparison string, starting from the beginning of the string, and the third parameter, which is the length to compare:

The code is as follows Copy Code

Echo strncasecmp ("ABCDD", "ABCDE", 3);

Returns 0, compares ABC and ABC, because it is not case sensitive, so the two are the same

PHP string Comparison We can also use = = to, as

The code is as follows Copy Code

$a = ' AA ';
$b = ' www.bKjia.c0m ';

if ($a = = $b)
{
echo ' equal ';
}
Else
{
echo ' unequal ';
}

You can also use = = = to compare

The code is as follows Copy Code

22 = = "22"; Returns True
22 = = = "22"; Returns false

http://www.bkjia.com/PHPjc/628890.html www.bkjia.com true http://www.bkjia.com/PHPjc/628890.html techarticle the use of the strcmp () function is to compare two strings, if two strings are exactly equal we return 0, otherwise there will be a variety of return values, this function is case-sensitive, the need for friends to participate ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.