Compare two strings using a "natural" algorithm (case-insensitive):
The strnatcasecmp() function compares two strings using a "natural" algorithm.
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.
Note: The strnatcasecmp() is case-insensitive.
| Parameter | Description |
|---|---|
| string1 | Required. Specifies the first string to compare |
| string2 | Required. Specifies the second string to compare |
| Return Value: | This function returns:
|
|---|---|
| PHP Version: | 4+ |
Difference between natural algorithm (strnatcmp) and regular computer string sorting algorithms (strcmp):
Complete PHP String Reference
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.