Home > Backend Development > PHP Tutorial > Comparison of php strings

Comparison of php strings

WBOY
Release: 2016-07-29 09:00:40
Original
1014 people have browsed it

int strcmp(string $str1, string $str2)

Note that this comparison is case-sensitive.

Parameters

str1The first string.

str2The second string.

Return value

If str1 is less than str2, return a negative number; if str1 is greater than str2, return a positive number; if they are equal, return 0. (Return 0 if equal)

Example:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

<?php

;​​​​​​​$var2=

"Hello"; ,$var2

)==0)

{echo'equal';                                                                                                 {                                                                                                                                                                ​            

}

?>

strcasecmp — Binary safe string comparison (case insensitive)

?

1

int

strcasecmp(string

$str1

,string

$str2

)

str1

The first string.

str2

The second string. Return value: If str1 is less than str2, return < 0; if str1 is greater than str2, return > 0; if they are equal, return 0. Example:<?php $var1="Hello"; $var2="hello"; if(strcasecmp($var1,$var2)==0){ echo'$var1isequalto$var2inacase-insensitivestringcomparison' ; } ?>

The above introduces the comparison of PHP strings, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.
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