English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strnatcmp() Function Usage and Example

PHP String Character String Functions Manual

The strnatcmp() function compares strings using a natural sorting algorithm (case-sensitive).

Syntax

int strnatcmp ( string $str1 , string $str2 )

Definition and Usage

It compares two strings using a natural order algorithm, case-sensitive.

Return Value

 Similar to other string comparison functions, if str1 Less than str2 Return < 0; if str1 Greater than str2 Return > 0; if they are equal, return 0.

Parameter

NumberParameters and Description
1

string1

The first string

2

string2

The second string

Online Example

Try the following example to compare the size of two strings:

<?php
//Case-sensitive comparison of two strings
echo strnatcmp("5w3codebox!","5w3codebox!);
echo "<br>";
//Case-sensitive comparison of two strings
echo strnatcmp("5w3codebox!","5w3codebox!);
echo "<br>";
//The second string is greater than the first string
echo strnatcmp("5w3codebox!","58w3codebox!);
echo "<br>";
//The second string is less than the first string
echo strnatcmp("101111w3codebox!","211w3codebox!);
?>
Test and see‹/›

Output Result

0
1
-1
1

PHP String Character String Functions Manual