The natsort() function is an inbuilt function in PHP which is used to sort an array by using a “natural order” algorithm. The natural order tells the order to be used as a normal human being would use. That is, it does not check the type of value for comparison. For example, in string representation 30 is less than 7 according to the standard sorting algorithm as 3 comes before 7 lexicographically. But in natural order 30 is greater than 7.
Parameters: This function accepts a single parameter $array. It is the array which natsort() function is going to sort.
Return Value: It returns a boolean value i.e., TRUE on success and FALSE on failure.
Below programs illustrate the natsort() function in PHP:
Standard sorting Array (  => 1.jpeg  => 10.jpeg  => 12.jpeg  => 2.jpeg ) Natural order sorting Array (  => 1.jpeg  => 2.jpeg  => 10.jpeg  => 12.jpeg )
Natural order sorting Array (  => gfg1.jpeg  => gfg2.jpeg  => gfg10.jpeg  => gfg15.jpeg  => gfg22.jpeg )
This article is attributed to GeeksforGeeks.org