从数组中删除elemets女儿在哪里数组的值等于

从数组中删除elemets女儿在哪里数组的值等于

本文介绍了从数组中删除elemets女儿在哪里数组的值等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组什么数组组成的。有一个长相到这个文件。结果
你怎么能看到每个阵列重复两次。我需要删除第二,我需要通过钥匙数组的值进行比较。结果
谢谢!

I have an array what consist of arrays. Have a looks into this file gist.
How you can see each array repeats two times. I need to delete the second, I need to compare them by 'key' value of array.
Thanks!

推荐答案

要得到期望的结果,最简单的方法是在我看来,这种方式:

The easiest way to get the result you expect is in my opinion this way:

$data = array(
    array(
        'domain' => 'messages',
        'key' => 'test.testik',
        'message' => array()
    ),
    array(
        'domain' => 'messages',
        'key' => 'test2313.tes31231tik',
        'message' => array()
    ),
    array(
        'domain' => 'validators',
        'key' => 'valid.validik',
        'message' => array()
    ),
    array(
        'domain' => 'validators',
        'key' => 'joga.jimbo',
        'message' => array()
    ),
    array(
        'domain' => 'validators',
        'key' => 'valid.validik',
        'message' => array()
    )
);
$newdata = array();

foreach ($data as $subdata) {
    $newdata[$subdata['key']] = $subdata;
}

$newdata = array_values($newdata); // reset array indizes

print_r($newdata);

这篇关于从数组中删除elemets女儿在哪里数组的值等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 17:56