Home  >  Article  >  Backend Development  >  How to determine whether strings are the same in php

How to determine whether strings are the same in php

青灯夜游
青灯夜游Original
2021-05-11 18:02:162751browse

In PHP, you can use the strcmp() function to determine whether the strings are the same. The syntax format is "strcmp(String 1, String 2)"; if the return value is 0, the strings are the same. If the return value is greater than 0, string 1 is greater than string 2. If the return value is less than 0, string 1 is less than string 2.

How to determine whether strings are the same in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

PHP determines whether two strings are consistent Not the same

In PHP, to determine whether two strings are consistent, it is recommended to use the strcmp() method:

$result="fail";
if (strcmp($result,"success" )==0) {
//相同
echo("<br>success");
}else{
//不相同
echo("<br>fail");
}

Description:

strcmp() function comparison Two strings.

Syntax

strcmp(string1,string2)
Parameters Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to be compared.
Return value: The function returns:
  • 0 - If two strings Equality
  • d590a015f33a3053aaa2fed41c9a4a800 - if string1 is greater than string2

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether strings are the same in php. 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