Home >Backend Development >PHP Tutorial >About comparison content of php strings

About comparison content of php strings

不言
不言Original
2018-07-05 16:31:131324browse

This article mainly introduces the comparison of PHP strings, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

int strcmp( string $str1 , string $str2 )

Pay attention to the comparisonDifferentiate sizeWrite.

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 , returns a positive number; if they are equal, 0 is returned. (Returns 0 if equal)

Example:

<?php
        $var1="Hello";
        $var2="Hello";
          
         if(strcmp($var1,$var2)==0)
         {echo&#39;相等&#39;;
         }
        else     {
                echo&#39;不相等&#39;;
        }
  
 
?>

strcasecmp —Binary safe comparison of strings (case insensitive)

int strcasecmp(string$str1,string$str2)
  • Return value: If str1 is less than str2, return d080f09270cf355b72114226f9621e90 0; if they are equal, return 0. str1

  • The first string.

  • str2

  • The second string.

Example:

<?php
  $var1="Hello";
  $var2="hello";
  if(strcasecmp($var1,$var2)==0){
  echo&#39;$var1isequalto$var2inacase-insensitivestringcomparison&#39;;
  }
  ?>

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to operate php files

Instances of php implementing PageRank

The above is the detailed content of About comparison content of php strings. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How to operate php filesNext article:How to operate php files