Results 1 to 4 of 4

Thread: Sorting an Array in PHP

  1. #1
    Join Date
    Aug 2009
    Posts
    40

    Sorting an Array in PHP

    I am looking for code which Sort an Array in PHP. PHP Arrays can be two, tree or more dimensional but how to sort the array values and from which function?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Sorting an Array in PHP

    Php array sort example :
    Code:
    <?php
    
    $narray[0]="Al";
    $narray[1]="Ro";
    $narray[2]="De";
    $narray[3]="Te";
    $narray[4]="Jo";
    $narray[5]="Ch";
    
    
    sort($narray);
    
    for($j=0; $j<6; $j++)
    {
    print $narray[$j] . "<br />";
    }
    
    ?>
    The output of this PHP code is:

    Al
    Ch
    De
    Jo
    Ro
    Te

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Sorting an Array in PHP

    While Sorting an Array in PHP you need to use two functions: sort(), to sort an array in ascending order (From A to Z), and rsort(), to sort an array in the reverse order, or descending order (From Z to A).

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Sorting an Array in PHP

    PHP sort() Function : This function assigns new keys for the elements in the array. Existing keys will be removed.This function allows sorting of an array of objects too <?php. . This is a simplest array sort function in PHP. This function make a simple sort of the array values.

Similar Threads

  1. sorting linkedlist
    By duper in forum Software Development
    Replies: 1
    Last Post: 05-06-2011, 03:30 AM
  2. Sorting a hashmap
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 05:06 AM
  3. Assigning an array to an array
    By MACE in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 05:19 PM
  4. XSL Sorting Question
    By pbrstreetgang in forum Software Development
    Replies: 1
    Last Post: 08-09-2009, 08:39 PM
  5. Array sorting in Excel
    By Kelsey in forum Software Development
    Replies: 3
    Last Post: 08-11-2008, 04:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,356,532.28279 seconds with 16 queries