Array Functions

PHP natcasesort() Function

Topic: PHP Array ReferencePrev|Next

Description

The natcasesort() function sorts an array using a case-insensitive "natural order" algorithm.

The keys are preserved, i.e. the key-to-value mapping will remain unchanged by the sort operation.

The following table summarizes the technical details of this function.

Return Value: Returns TRUE on success or FALSE on failure.
Version: PHP 4+

Syntax

The basic syntax of the natcasesort() function is given with:

natcasesort(array);

The following example shows the natcasesort() function in action.

<?php
// Sample array
$images = array("IMG5.png", "img10.png", "IMG2.png", "img1.png");

// Standard sorting
sort($images);
print_r($images);

// Natural order sorting
natcasesort($images);
print_r($images);
?>

Tip: The natcasesort() function implements a sort algorithm that orders the alphanumeric strings in the way a human being would. This is described as a "natural ordering".


Parameters

The natcasesort() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to be sorted.
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties