Example of string comparison function strcmp() in php

一个新手
Release: 2023-03-16 14:18:01
Original
1478 people have browsed it

int strcmp (string $str1, string $str2)

Compare in binary mode
Comparison with this function is case-sensitive
Return value, if str1 If it is less than str2, it returns <0. If str1 is greater than str2, it returns >0. If they are equal, it returns 0.

<?php    
    $str1 = "hello world";    //$str1与$str3的值相等
    $str2 = "HELLO WORLD";    
    $str3 = "hello world";    //$str1与$str3的值相等

    echo strcmp($str1,$str2);    //输出1
    echo strcmp($str2,$str1);    //输出-1
    echo strcmp($str1,$str3);    //输出0
?>
Copy after login

There is also a function strcasecmp(), the usage is similar to strcmp(), except that it is not case-sensitive, so I won’t go into details here

The above is the detailed content of Example of string comparison function strcmp() in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template