strnatcmp

int strnatcmp(string string_one, string string_two) 

Compares strings using a “natural” algorithm.

Returns:

Integer

Description:

strnatcmp() compares strings in much the same fashion as a human would. Numbers are ordered by their value, instead of by their character value.

Version:

PHP 4.0RC2+

See also:

To perform non-case-sensitive natural string comparison:

strnatcasecmp() 

For additional information on natural sorting:

Martin Pool’s Natural Order String Comparison

www.linuxcare.com.au/projects/natsort/

Example:

Compare a list of values
 <?php $strings = array ("one", 1, "01", 2001, "two-thousand and one"); foreach ($strings as $string_one) { foreach ($strings as $string_two) { $comparison = strnatcmp ($string_one, $string_two); ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.