Array ( [0] => Array ( [message_email] => test3@test.com [message_subject] => p message2 [message_date] => 2011-06-02 00:00:00 [message_id] => 4 [message_name] => test name2 [user_id] => 26 [user_display] => Administrator ) [1] => Array ( [message_email] => test@test.com [message_subject] => test product sub1 [message_date] => 2011-06-01 00:00:00 [message_id] => 3 [message_name] => tet name1 [user_id] => 26 [user_display] => Administrator ) )
For eg: I need to sort this multidimensional array based on the message_name
in ascending order.
So I put
$sort = "message_name";
$order_by = "asc";
$asc = create_function ('$a,$b','return strcasecmp($a["'.$sort.'"], $b["'.$sort.'"]);');
$desc = create_function ('$a,$b','return strcasecmp($b["'.$sort.'"], $a["'.$sort.'"]);');
if($order_by=="asc")
usort($rows,$asc);
else
usort($rows,$desc);
print_r($rows)
Hope this will help some one.. :)
No comments:
Post a Comment