Sorting array of array by value in php -
this question has answer here:
- how can sort arrays , data in php? 7 answers
i have array named $result have contents this:
array ( [1114_435] => stdclass object ( [uid] => 435 [v_first_name] => fherter [v_last_name] => herter [id] => 1114 [v_title] => morning stretch [fk_resident_id] => 435 [v_location] => front lawn [i_started_date] => 1357054200 ) [1114_444] => stdclass object ( [uid] => 444 [v_first_name] => fxyz [v_last_name] => xyz [id] => 1114 [v_title] => morning stretch [fk_resident_id] => 444 [v_location] => front lawn [i_started_date] => 1357054200 ) [1114_448] => stdclass object ( [uid] => 448 [v_first_name] => fdavidson [v_last_name] => davidson [id] => 1114 [v_title] => dinner [fk_resident_id] => 448 [v_location] => front lawn [i_started_date] => 1357051000 ) )
i want sort on basis of i_started_date. tried using ksort, asort etc no luck, maybe wasn`t using properly. highly appreciated.
thanks!
try this:
function sortarray($data) { $sortarray = array(); foreach($data $dt) { foreach($dt $key=>$value) { if(!isset($sortarray[$key])) { $sortarray[$key] = array(); } $sortarray[$key][] = $value; } } $orderby = "1"; //change whatever key want array array_multisort($sortarray[$orderby],sort_asc,$data); return $data; }
Comments
Post a Comment