How to determine whether strings are the same in php

青灯夜游
Release: 2023-03-09 16:04:01
Original
2736 people have browsed it

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("
success"); }else{ //不相同 echo("
fail"); }
Copy after login

Description:

strcmp() function comparison Two strings.

Syntax

strcmp(string1,string2)
Copy after login
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
  • <0 - if string1 is less than string2
  • >0 - 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!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!