我有一个多维数组:
[everything_list] => Array
(
[follow] => Array
(
[2] => Array
(
[username] => 3333
[username_image] => qykhgz4861sna14af6h6mpage_f4a.jpg
[follow_username] => 6666
[follow_image] => flw3utn9igiqh7dtt2o61ydf8_174.jpeg
[date] => 1329183703
)
[3] => Array
(
[username] => 3333
[username_image] => qykhgz4861sna14af6h6mpage_f4a.jpg
[follow_username] => 8888
[follow_image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[date] => 1329168868
)
[4] => Array
(
[username] => 6666
[username_image] => flw3utn9igiqh7dtt2o61ydf8_174.jpeg
[follow_username] => 8888
[follow_image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[date] => 1328221789
)
[5] => Array
(
[username] => 8888
[username_image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[follow_username] => 6666
[follow_image] => flw3utn9igiqh7dtt2o61ydf8_174.jpeg
[date] => 1328219453
)
[6] => Array
(
[username] => 8888
[username_image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[follow_username] => Kolxoznik1
[follow_image] =>
[date] => 1328218207
)
[7] => Array
(
[username] => 8888
[username_image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[follow_username] => 3333
[follow_image] => qykhgz4861sna14af6h6mpage_f4a.jpg
[date] => 1328217742
)
)
[pictures] => Array
(
[0] => Array
(
[user] => 8888
[user_image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[image_id] => 5
[text] =>
[date] => 1329072315
[comments] => 2
[first_image_id] => 4
)
[1] => Array
(
[user] => 8888
[user_image] => nsm5rixy14lexm9cy15wzyg9u_224.jpg
[image] => 0j1kjjzdv3ez07a0ee4lnmjb7_163.jpeg
[image_id] => 4
[text] =>
[date] => 1328577934
[comments] => 0
[first_image_id] => 4
)
)
我想按日期对这个数组进行排序,得到类似的结果:
[follow] => Array
{
....
}
[pictures] => Array
{
....
}
[follow] => Array
{
....
}
答案 0 :(得分:2)
选中此Sorting a multidimensional array希望它会有所帮助
答案 1 :(得分:0)
如果我理解你的问题,这样的事情就应该这样做
function orderByDate($a, $b)
{
return $a['date'] < $b['date'];
}
$newArray = $array['everything_list']['follow'] + $array['everything_list']['pictures'];
usort($newArray, 'orderByDate');