Home  >  Article  >  Backend Development  >  How to use strnatcasecmp function

How to use strnatcasecmp function

藏色散人
藏色散人Original
2019-02-01 09:52:552048browse

PHP strnatcasecmp function: Use the "natural order" algorithm to compare strings (not case-sensitive)

How to use strnatcasecmp function

php strnatcasecmp() function syntax

Function : Use the "natural" algorithm to compare two strings (case-insensitive):

Syntax:

strnatcasecmp(string1,string2)

Parameters:

string1 Required, specifies the number to be compared a string.

string2 Required, specifies the second string to be compared.

Description: The strnatcasecmp() function uses a "natural" algorithm to compare two strings. In natural arithmetic, 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. strnatcasecmp() is not case sensitive. If the two strings are equal, 0 is returned. If string1 is greater than string2, the returned value is greater than 0. If string1 is less than string2, the returned value is less than 0

php strnatcasecmp() function usage example:

<?php
echo strnatcasecmp("2hello world!","01hello world!");
echo "<br>";
echo strnatcasecmp("01hello world!","2hello world!");
?>

Output:

1
-1

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

The above is the detailed content of How to use strnatcasecmp function. 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