I have a multilevel array as below
array(
(int)0=>array(
'User' => array(
'PostType' => array(
'PHP' => array(
'id' => '2',
'type_title' => 'Core Questions',
'type_description' => 'none',
'type_sort_order' => '7'
'Post'=>array(
......
),
),
'ASP' => array(
'id' => '1',
'type_title' => 'Core Questions',
'type_description' => 'none',
'type_sort_order' => '1'
'Post'=>array(
......
),
),
),
)));
I have fetched a user with its post categorized by postType
postType has type_sort_order field
I want to sort sub array PostType by type_sort_order field
so that ASP come before PHP
I tried usort as below
usort($arr,function(){
return ($a[0]['User']['PostType']['post_sort_order'] < $b[0]['User']['PostType']['post_sort_order'])?1:-1;
});
and also many other sort but not getting correct result