Home > Backend Development > PHP Problem > What does strcmp in PHP mean?

What does strcmp in PHP mean?

藏色散人
Release: 2023-02-25 21:44:02
Original
3248 people have browsed it

What does strcmp in PHP mean?

What does strcmp in PHP mean?

Definition and usage

strcmp() function compares two strings.

Note: The strcmp() function is binary safe and case-sensitive.

Tip: This function is similar to the strncmp() function, except that with strncmp() you can specify the number of characters for each string to be compared.

Syntax

strcmp(string1,string2)
Copy after login

Parameters

string1 Required. Specifies the first string to compare.

string2 Required. Specifies the second string to be compared.

Return value:

This function returns:

0 - if the two strings are equal

<0 - if string1 is less than string2

>0 - if string1 is greater than string2

Example 1

Compare two strings (case sensitive, Hello and hELLo output are not the same):

<?php
echo strcmp("Hello","Hello");
echo "<br>";
echo strcmp("Hello","hELLo");
?>
Copy after login

Output:

0
-1
Copy after login

Example 2

Different return values:

<?php
echo strcmp("Hello world!","Hello world!"); // 两字符串相等
echo strcmp("Hello world!","Hello"); // string1 大于 string2
echo strcmp("Hello world!","Hello world! Hello!"); // string1 小于 string2
?>
Copy after login

Output:

0
7
-7
Copy after login

For more PHP knowledge, please Visit PHP Chinese website!

The above is the detailed content of What does strcmp in PHP mean?. 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