Friday 28 March 2014

Sort Array values using specific(particuler) Key of array

function sort_arr_of_obj($array, $sortby, $direction='asc') {
   
    $sortedArr = array();
    $tmp_Array = array();
   
    foreach($array as $k => $v) {
        $tmp_Array[] = strtolower($v[$sortby]);
    }
   
    if($direction=='asc'){
        asort($tmp_Array);
    }else{
        arsort($tmp_Array);
    }
   
    foreach($tmp_Array as $k=>$tmp){
        $sortedArr[] = $array[$k];
    }
   
    return $sortedArr;

}

$myArray=array(0=>array('size'=>5,'name'=>'Five'),1=>array('size'=>3,'name'=>'Three'),2=>array('size'=>9,'name'=>'Nine'));
$myArray=sort_arr_of_obj($myArray,'size','asc');


No comments:

Post a Comment

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...