php8.5
Home/ Manual/ strings / functions/ strnatcasecmp

strnatcasecmp

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Case insensitive string comparisons using a "natural order" algorithm

Description

strnatcasecmp(string $string1, string $string2): int

This function implements a comparison algorithm that orders alphanumeric strings in the way a human being would. The behaviour of this function is similar to strnatcmp(), except that the comparison is not case sensitive. For more information see: Martin Pool's Natural Order String Comparison page.

Parameters

string1

The first string.

string2

The second string.

Return Values Return

Changelog

VersionDescription

Examples

strnatcasecmp() example

php
<?php

var_dump(strnatcasecmp('Apple', 'Banana'));
var_dump(strnatcasecmp('Banana', 'Apple'));
var_dump(strnatcasecmp('apple', 'Apple'));
?>

The above example will output:

output
int(-1)
int(1)
int(0)

See Also

Source: reference/strings/functions/strnatcasecmp.xml · from the official PHP manual (php/doc-en)