在具有不同字段数的集合中搜索公共值

时间:2018-11-30 22:21:31

标签: php arrays php-7.2

我有两个数组。
例子:

  array:4 [▼
      0 => array:3 [▼
        "title" => "News"
        "created_at" => "2018-11-29 20:05:35"
        "updated_at" => "2018-11-29 20:05:35"
      ]
    ]
    array:2 [▼
      0 => array:4 [▼
        "title" => "News"
        "created_at" => "2018-11-29 20:05:35"
        "updated_at" => "2018-11-29 20:05:35"
        "pivot" => array:2 [▶]
      ]
    ]

如何将in_array函数应用于此类数组? 我试图找到共同的价值观:

 $tags=Tag::get(['title','created_at','updated_at'])->toArray();
        dump($tags);
        $newsTag=$new->tags();
        $newsTag=$newsTag->get(['title','created_at','updated_at'])->toArray();
        dump($newsTag);
        foreach ($tags as $tag){
            if(in_array($tag,$newsTag)){
                echo $tag->name;
                echo "1";
                }
        }

0 个答案:

没有答案