Home  >  Article  >  Backend Development  >  Usage of strcmp function in php

Usage of strcmp function in php

藏色散人
藏色散人Original
2020-04-25 13:38:082918browse

Usage of strcmp function in php

strcmp function usage in php

strcmp definition and usage

## The #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)

Parameters

string1 Required. Specifies the first string to compare.

string2 Required. Specifies the second string to be compared.

Usage of strcmp function in php

Example 1

Compare two strings (case sensitive, Hello and hELLo output are different):

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

Output:

0
-1

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
?>

Output:

0
7
-7

The above is the detailed content of Usage of strcmp function 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