How to remove duplicate data of JSON object using PHP

前端 未结 3 1544
[愿得一人]
[愿得一人] 2020-12-11 07:17

I need one help.I have some JSON type data and i want to remove the duplicate set of data using PHP.I am explaining my code below.

data=[
   {\'member_name\'         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 08:06

    I was faced with the same challenge, so I came up with this simple solution.

    dataArray = $dataArray;
            $this->indexToFilter = $indexToFilter;
        }
        private function getUnique(){
            foreach($this->dataArray as $key =>$value){
                $id[$value[$this->indexToFilter]]=$key;
            }
            return array_keys(array_flip(array_unique($id,SORT_REGULAR)));
        }
        public function getFiltered(){
            $array = $this->getUnique();
            $i=0;
            foreach($array as $key =>$value){
                $newAr[$i]=$this->dataArray[$value];
                $i++;
            }
            return $newAr;
        }
    }
    ?>
    

    include the class in your invocation code and that's all

    getFiltered() );
    
    #Let the World See it :)
    echo $result;
    ?>
    

提交回复
热议问题