How to use php strcmp function

藏色散人
Release: 2023-04-04 22:54:02
Original
11420 people have browsed it

php The strcmp function is used for binary safe string comparison. Its syntax is strcmp(string1,string2). The parameter string1 must be the first string to be compared, and string2 must be the second string to be compared. String.

How to use php strcmp function

#php How to use strcmp function?

Function: Compare two strings (case sensitive)

Syntax:

strcmp(string1,string2)
Copy after login

Parameters:

string1 Required, specified to be compared the first string.

string2 Required, specifies the second string to be compared.

Description: The strcmp() function compares two strings. The strcmp() function is binary-safe and case-sensitive. If the two strings are equal, 0 is output. If string1 is less than string2, the output value is less than 0. If string1 is greater than string2, the output value is greater than 0.

php strcmp() function usage example 1:

<?php
$i = "Hello world";
$j = "HELLO WORLD";
echo strcmp($i,$j);
?>
Copy after login

Output:

1
Copy after login

php strcmp() function usage example 2:

<?php
echo strcmp("str1", "str2");
?>
Copy after login

Output:

-1
Copy after login

This article is an introduction to the PHP strcmp function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php strcmp function. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template