【发布时间】:2019-04-29 17:26:57
【问题描述】:
我需要一个按 Unix 时间戳值排序的数组。我尝试同时使用ksort 和krsort,然后才意识到有时时间戳值可能相同(并且数组中不能有重复的键)。
这是我可能会遇到的一个示例数组:
$array = array(
[
"unix" => 1556547761, // notice the two duplicate unix values
"random" => 4
],
[
"unix" => 1556547761,
"random" => 2
],
[
"unix" => 1556547769,
"random" => 5
],
[
"unix" => 1556547765, // this should be in the 3rd position
"random" => 9
]
);
所以我要做的是根据每个子数组unix 值对它们进行排序,但是我不知道该怎么做。我尝试了无数疯狂的方法(包括所有其他 sort 函数和许多很多 for 循环)来弄清楚 - 但无济于事。
感谢所有帮助。
【问题讨论】: