PHP 二维数据去重

         $tj_recommend = [
            ['id' => 1, 'files_id' => 1],
            ['id' => 2, 'files_id' => 3],
            ['id' => 3, 'files_id' => 3],
            ['id' => 4, 'files_id' => 2],
            ['id' => 5, 'files_id' => 5],
            ['id' => 6, 'files_id' => 1],
            ['id' => 7, 'files_id' => 7],
            ['id' => 8, 'files_id' => 8],
            ['id' => 9, 'files_id' => 1]
        ];
        $arr = [];
        foreach($tj_recommend as $item){
            if(!in_array($item['files_id'], array_column($arr, 'files_id'))){
                $arr[] = $item;
            }
        }
        print_r($arr);exit;

34 thoughts on “PHP 二维数据去重”

  1. Normally I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very nice article.

  2. Today, I went to the beach front with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Back To Top

鄂ICP备17008157号-1