PHP natcasesort() function

PHP list() function
PHP natsort() function

In this article, you will learn how to sort an array in the natural order. In Natural Order, the number 2 is less than the number 10. But in computer sorting, the number 10 is less than 2 because the first digit in 10 is 1 which is less than 2.

The natcasesort () function rearranges the elements of an array in natural order using natural order algorithm.

This function is case-insensitive.

What is the syntax of the natcasesort() function in PHP?

natcasesort(array)
ParameterDetails
arrayThe array to sort the elements of – Required
PHP natcasesort() function

Example of natcasesort function

Example 1. Arrange the elements of the array in the natural order.

<?php
arr = ["day1","day2","day3","day4","day5"];
natsort($arr);
echo "Natural order:";
print_r($arr);
?>

Example 2. Case-insensitive behavior of natcasesort function.

<?php
arr = ["day1","day2","day3","day4","day5"];
natcasesort($arr);
echo "Natural order: ";
print_r($arr);
?>

PHP list() function
PHP natsort() function
en English
X
Scroll to Top