基于值(而不是数组键)唯一的多维数组
我有一个多维数组,我需要对其进行唯一性排序,因为我有重复的记录,因此我需要 array_unique
遍历数组并按值删除重复项,例如
Array
(
[0] => Array
(
[id] => 324
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
[1] => Array
(
[id] => 325
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
[2] => Array
(
[id] => 326
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
)
有重复的 time_start
,它们都是相同的,还有 level
和 input_level
,但只有当有匹配的 time_start
时,它们才不会受到影响> 它应该删除它并处理整个数组(该数组比您想象的要大,但我只是发布了该数组的一个小示例)。应该删除重复项并像这样返回:
Array
(
[0] => Array
(
[id] => 324
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
)
我发现不起作用的问题:
I have a multidimensional array which I need to be sorted with uniqueness as I have duplicated records, so I need array_unique
to go through the array and remove duplicates by the value, e.g.
Array
(
[0] => Array
(
[id] => 324
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
[1] => Array
(
[id] => 325
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
[2] => Array
(
[id] => 326
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
)
There are duplicated time_start
, which they are all the same, also level
and input_level
but they are not to be affected, only if there are matching time_start
it should remove it and process the whole array (the array is bigger than you think, but I just posted a small example of the array). Should remove dupes and return like this:
Array
(
[0] => Array
(
[id] => 324
[time_start] => 1301612580
[level] => 0.002
[input_level] => 0.002
)
)
Questions I've found that didn't work:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
或者
or
使用
array_filter()
来过滤基于回调结果的数组(我使用了一个从 PHP 5.3 开始就可以使用的匿名函数)。time_start
值被收集到一个临时数组中。Uses
array_filter()
which will filter an array based on the result of a callback (I used an anonymous function which can be used since PHP 5.3). Thetime_start
values are collected into a temporary array.我想你只需要步行:
I think you'll just have to walk it: