用于嵌套数组的PHP唯一数组函数 [英] PHP unique array function for nested array

查看:128
本文介绍了用于嵌套数组的PHP唯一数组函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用Array_unique函数为嵌套数组工作如下?我想要摆脱日期重复,并获得两个日期作为数组...

Is there a way to use Array_unique function working for nested array like below? I want to get rid of date duplicates and get two dates out as an array...

Array
(
    [0] => Array
        (
            [value] => 1311044688
            [name] => 19th Jul 2011
        )

    [1] => Array
        (
            [value] => 1311044919
            [name] => 19th Jul 2011
        )

    [2] => Array
        (
            [value] => 1311045076
            [name] => 19th Jul 2011
        )

    [3] => Array
        (
            [value] => 1311164873
            [name] => 20th Jul 2011
        )

    [4] => Array
        (
            [value] => 1311165000
            [name] => 20th Jul 2011
        )

)


推荐答案

作为键,并且值作为值。

I'd write this array to another array using the date as the keys, and the "values" as the value. That's probably the fastest way to achieve what you're looking for.

有点像:

$uniqueAry = array()
foreach ($ary as $item) {
  $uniqueAry[$item['name']] = $item['value'];
}

您可能需要包含一点逻辑,

You'd probably want to include a bit of logic to determine which value takes precedence in case of dupes.

这篇关于用于嵌套数组的PHP唯一数组函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆