How to reject duplicate data and sort a JSON type object value using PHP -


i need 1 help.i need reject duplicate data ans sort values present inside json object using php.i explaining code below.

$res[]=array('member_name'=>$member,'no_of_members'=>$rowno['cnt'],'member_type'=>$countmemb); 

the output of $res given below.

[   {member_name:"medilink member",member_type:"1",no_of_members:"383"},   {member_name:"medilink member",member_type:"1",no_of_members:"383"},   {member_name:"medilink member",member_type:"1",no_of_members:"383"},   {member_name:"non-medilink member",member_type:"2",no_of_members:"24"},   {member_name:"non-medilink member",member_type:"2",no_of_members:"24"}  ] 

i need reject duplicate row above , result value format should come below.

$res=[     {member_name:"medilink member",member_type:"1",no_of_members:"383"},     {member_name:"non-medilink member",member_type:"2",no_of_members:"24"} ] 

i need result given above.please me resolve problem.

you need remove duplicate records first multidimensional array , can use json_encode getting results in json format

<? // array $res[]=array('member_name'=>'medilink member','no_of_members'=>1,'member_type'=>383); $res[]=array('member_name'=>'medilink member','no_of_members'=>1,'member_type'=>383); $res[]=array('member_name'=>'medilink member','no_of_members'=>1,'member_type'=>383); $res[]=array('member_name'=>'non-medilink member','no_of_members'=>2,'member_type'=>24); $res[]=array('member_name'=>'non-medilink member','no_of_members'=>2,'member_type'=>24);  // remove duplicates using array_map , array_unique multidimensional array $duplicateremoved = array_map("unserialize", array_unique(array_map("serialize", $res)));  // rearrange array $rearrangearray = array_values($duplicateremoved);  // encode unique array json format     $encodeddata = json_encode($rearrangearray);  // print result     echo $encodeddata;     ?> 

Comments