how to sort multiple array in php
multiple array sorting using php
<?php
$multiArray = Array(
Array("id" => 1, "name" => "Defg","add"=>"adstes"),
Array("id" => 4, "name" => "Abcd","add"=>"tes"),
Array("id" => 3, "name" => "Bcde","add"=>"des"),
Array("id" => 2, "name" => "Cdef","add"=>"cad"));
function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
asort($sorter);
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
}
aasort($multiArray,"id");
echo "<pre>";print_r($multiArray);
?>
multiple array sorting using php
<?php
$multiArray = Array(
Array("id" => 1, "name" => "Defg","add"=>"adstes"),
Array("id" => 4, "name" => "Abcd","add"=>"tes"),
Array("id" => 3, "name" => "Bcde","add"=>"des"),
Array("id" => 2, "name" => "Cdef","add"=>"cad"));
function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
asort($sorter);
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
}
aasort($multiArray,"id");
echo "<pre>";print_r($multiArray);
?>
multiple array sorting using php
Comments
Post a Comment