_php Tutorial for string comparison methods in PHP

Source: Internet
Author: User
This article introduces one or two kinds of character comparison methods in PHP, one is = = number, one is the strcmp function for string equality comparison, the need for friends can refer to.

Compare using the function strcmp () function string


int strcmp (string str1,string str2))
The parameter str1 and the parameter str2 the two strings to compare, or 0 if they are equal, if the parameter str1 is greater than the parameter str2 the return value is greater than 0, and the return value is less than 0 if the parameter str1 is less than the parameter str2.

Instance:

The code is as follows Copy Code
$str 1= "a"; Defining string Constants
$str 2= "B"; Defining string Constants
$str 3= "CCC"; Defining string Constants
$str 4= "CCC"; Defining string Constants
Echo strcmp ($str 1, $str 2);//The two strings are equal
Echo strcmp ($str 3, $str 4);//Note that this function is case-sensitive
?>

Note: This function distinguishes the case of letters.

Use = = to compare

The code is as follows Copy Code

$a = "Joe";
$b = "Jerry";
if ($a! = $b)
{
echo "Unequal";
}
Else
{
echo "equal";
}

For more detailed information, please see: http://www.bKjia.c0m/phper/php-function/35413.htm

http://www.bkjia.com/PHPjc/629266.html www.bkjia.com true http://www.bkjia.com/PHPjc/629266.html techarticle This article introduces one or two kinds of character comparison methods in PHP, one is = = number, one is the strcmp function for string equality comparison, the need for friends can refer to. Using the function strcmp () function ...

  • 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.