Home > Backend Development > PHP Tutorial > Summary of usage of php strnatcmp() function_PHP tutorial

Summary of usage of php strnatcmp() function_PHP tutorial

WBOY
Release: 2016-07-13 17:17:51
Original
957 people have browsed it

Definition and Usage
Definition and Usage
The strnatcmp() function compares two strings using a "natural" algorithm. Rules compare strings (case sensitive).

In a natural algorithm, the number 2 is less than the number 10. In computer sorting, 10 is less than 2, because the first number in "10" is less than 2.

In "natural algorithm" Medium, 2 is smaller than 10. In the computer sequence, 10 is smaller than 2 because the first number in "10" is "1", which is smaller than 2.

This function returns:

This function will return the following values:

•0 - if the two strings are equal

0 - if the strings are equal
•<0 - if string1 is less than string2
<0 - if string1 is less than string2
• >0 - if string1 is greater than string2
>0 - if string1 is greater than string2
Syntax
Syntax

Copy code The code is as follows:
strnatcmp(string1,string2)

Parameter parameter Description
string1 Required. Specifies the first string to compareRequired parameter. Specify the first string object to be compared
string2 Required. Specifies the second string to compare
Parameter参数 Description描述
string1 Required. Specifies the first string to compare
必要参数。指定参与比较的第一个字符串对象
string2 Required. Specifies the second string to compare
必要参数。指定参数比较的第二个字符串对象
Required parameter. Specify the second string object for parameter comparison

Tips and Notes
Notes
Note: The strnatcmp() is case-sensitive.
Note: The strnatcmp() function is case-sensitive.

-------------------------------------------------- ----------------------------------

Example
Case

Copy code The code is as follows:

";echo strnatcmp("10Hello world!","2Hello world!");?>

The output of the code above will be:
The above code will output the following result: -1 1

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621719.htmlTechArticleDefinition and Usage The strnatcmp() function compares two strings using a "natural" algorithm. strnatcmp() The function is to compare strings using natural algorithms (...
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