本文介绍了php按值从多维数组中删除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按值删除重复项,正如您从 list_title 中看到的那样.我知道有几个问题和答案,但他们的解决方案对我不起作用.

I would like to remove duplicates by value as you can see from the list_title. I know there are several questions and answers to this but their solution doesn't work for me.

这是我尝试过的:

$uniqueArray = array_map("unserialize", array_unique(array_map("serialize", $notify)));

结果:

Array
(
[0] => Array
    (
        [list_id] => 86
        [list_reference] => 130948
        [list_title] => Offer:  apartment 2+kk
        [list_city] => Prague
        [list_date] => 2017-03-03 11:20:35
        [list_status] => 0
        [list_creator] => Company A
        [list_price] => 30000
        [list_furniture] => ["1","0","0"]
        [list_accommodation] => flat
    )

[1] => Array
    (
        [list_id] => 87
        [list_reference] => 130947
        [list_title] => Offer:  apartment 2+kk
        [list_date] => 2017-03-03 11:20:35
        [list_status] => 0
        [list_creator] => Company B
        [list_price] => 30000
        [list_furniture] => ["1","0","0"]
        [list_accommodation] => flat
    )

[2] => Array ...

由于标题,预期结果应该是其中之一:

Expected result should be one of those because of the title:

Array
(
[0] => Array
(
    [list_id] => 86
    [list_reference] => 130948
    [list_title] => Offer:  apartment 2+kk
    [list_city] => Prague
    [list_date] => 2017-03-03 11:20:35
    [list_status] => 0
    [list_creator] => Company A
    [list_price] => 30000
    [list_furniture] => ["1","0","0"]
    [list_accommodation] => flat
)

推荐答案

谢谢大家,有时过度思考会影响常识.

Thanks everyone, sometimes over-thinking can affect common sense.

我只是从 MYSQL 查询中解决了它,例如:

I simply solved it from MYSQL query with something like:

 GROUP BY list_title ORDER BY list_date

这篇关于php按值从多维数组中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 19:17