Ad Code

Ticker

6/recent/ticker-posts

how to sort array in php

Sort PHP Array

how to sort array in php


There is some predefined PHP functions for array sorting. These functions perform different type sorting for the array:-

Function name Sorts by Order of sort Related functions
array_multisort() value first array or sort options array_walk()
asort() value low to high arsort()
arsort() value high to low asort()
krsort() key high to low ksort()
ksort() key low to high asort()
natcasesort() value natural, case insensitive natsort()
natsort() value natural natcasesort()
rsort() value high to low sort()
shuffle() value random array_rand()
sort() value low to high rsort()
uasort() value user defined uksort()
uksort() key user defined uasort()
usort() value user defined uasort()

Examples of these functions:-

1. array_multisort()

    This function used many types and sort indexed array, associative array, and multiple arrays at a time. Normally it sort in ascending order, see the example:-
$data=array("A","D","H","B","Z");
array_multisort($data);
print_r($data);
//output:-
Array ( [0] => A [1] => B [2] => D [3] => H [4] => Z )

2. asort()

This function sort according to the value of all types of array and it is sorted in ascending order of array values, see the example:-

$agedata=array("amit"=>"45","dinesh"=>"55","ramu"=>"25");
asort($agedata);

//output:-

Array ( [ramu] => 25 [amit] => 45 [2] => D [dinesh] => 55 [4] => Z )

Post a Comment

6 Comments

  1. GlassWire Elite Crack is a powerful program to discover hidden threats on your computer. This program efficiently detects a malware, .GlassWire Pro Elite Crack

    ReplyDelete
  2. Step 2: Open the Application "Beyond Compare 4". Navigate To "Help >> Enter Key". Step 3: Paste the Above mentioned Key again. Now, it should Activate. Thanks .Beyond Compare 3 Key

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. You are constantly manifesting your reality, even if you are not always aware of it. According to the Law of Attraction, like attracts like. The .How-To-Manifest-A-Car-With-The-Law-Of-Attraction

    ReplyDelete

Ad Code