natsort() function in PHP


The natsort() function sorts an array using a "natural order" algorithm.

Syntax

natsort(arr)

Parameters

  • arr − The array to sort

Return

The natsort() function returns TRUE on success, or FALSE on failure.

Example

The following is an example −

 Live Demo

<?php
$stu_rank = array("rank10","rank2","Rank3","rank1","Rank7","rank4");
natsort($stu_rank);
print_r($stu_rank);
?>

Output

The following is the output −

Array
(
[2] => Rank3
[4] => Rank7
[3] => rank1
[1] => rank2
[5] => rank4
[0] => rank10
)

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Dec-2019

36 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements