About comparison content of php strings

不言
Release: 2023-04-02 15:20:02
Original
1284 people have browsed it

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 )
Copy after login

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;;
        }
  
 
?>
Copy after login

strcasecmp —Binary safe comparison of strings (case insensitive)

int strcasecmp(string$str1,string$str2)
Copy after login
  • Return value: If str1 is less than str2, return < 0; if str1 is greater than str2, return > 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;;
  }
  ?>
Copy after login

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!

Related labels:
php
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