Sort an array in PHP

Description

The following code shows how to sort an array.

Example


  //from w  w  w .java 2 s .  com
<?php
    $temp_files = array("t15.txt","t10.txt","t1.txt","t22.txt","t2.txt");
    
    sort($temp_files);
    echo "Standard sorting: ";
    print_r($temp_files);
    echo "<br>";
    
    natsort($temp_files);
    echo "Natural order: ";
    print_r($temp_files);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone