Example of a string comparison function strcmp () in PHP

Source: Internet
Author: User
Tags strcmp
int strcmp (String $str 1, String $str 2)

Compare in binary mode
Case-sensitive when compared to this function
The return value if STR1 is less than str2 returns <0 if STR1 is greater than str2 returns >0 if the two equals return 0.


<?php    $str 1 = "Hello World";    $str 1 equals the value of $str3    $str 2 = "HELLO World";    $str 3 = "Hello World";    $str 1 is equal to the value of $STR3    echo strcmp ($str 1, $str 2);    Output 1    echo strcmp ($str 2, $str 1);    Output-1    echo strcmp ($str 1, $str 3);    Output 0?>

There is also a function strcasecmp (), the usage is similar to the strcmp (), but is not case-insensitive, here no longer wordy

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.