设为首页 加入收藏

TOP

php中常用的字符串比较函数strcmp()实例解释
2017-10-09 13:23:56 】 浏览:3186
Tags:php 常用 字符串 比较 函数 strcmp 实例 解释

int strcmp ( string $str1 , string $str2 )

以二进制方式进行比较
以该函数比较时区分大小写
返回值,如果str1小于str2返回<0,如果str1大于str2返回>0如果两者相等返回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
?>

还有个函数strcasecmp(),用法与strcmp()类似,只是不区分大小写而已,这里不再啰嗦了

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PHP引用(&)使用详解 下一篇没有了

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目