[{
"sys_id": "2015-07-018",
"account_id": "2015-07-018",
"Names": [{
"fname": "Jackie",
"mname": "Lee",
"lname": "Chan",
"suffix": "Jr",
"city": "Tokyo",
"town": "Shinagawa-ku",
"dstrct": "District 2",
"street": "Jr",
"contactnum": "1234"
}, {
"fname": "Jackie",
"mname": "Lee",
"lname": "Chan",
"suffix": "Jr",
"city": "Tokyo",
"town": "Shinagawa-ku",
"dstrct": "District 2",
"street": "Jr",
"contactnum": "1234"
}, {
"fname": "Jackie",
"mname": "Lee",
"lname": "Chan",
"suffix": "Jr",
"city": "Tokyo",
"town": "Shinagawa-ku",
"dstrct": "District 2",
"street": "Jr",
"contactnum": "1234"
}, {
"fname": "Jackie",
"mname": "Lee",
"lname": "Chan",
"suffix": "Sr",
"city": "Tokyo",
"town": "Shinagawa-ku",
"dstrct": "District 2",
"street": "Sr",
"contactnum": "1234"
}, {
"fname": "Jackie",
"mname": "Lee",
"lname": "Chan",
"suffix": "Sr",
"city": "Tokyo",
"town": "Shinagawa-ku",
"dstrct": "District 2",
"street": "Sr",
"contactnum": "1234"
}, {
"fname": "Jackie",
"mname": "Lee",
"lname": "Chan",
"suffix": "Sr",
"city": "Tokyo",
"town": "Shinagawa-ku",
"dstrct": "District 2",
"street": "Sr",
"contactnum": "1234"
}]
}]
THis my result from ajax request i want to remove the duplicate from the result either from server side or jquery side in my server side i have tried the most common way of removing duplicated array like
$input = array_map("unserialize", array_unique(array_map("serialize", $new_data)));
$new_data1 = array_values($input);
echo json_encode($new_data1, JSON_UNESCAPED_UNICODE);
Where in the $new_data
is the result of my select query. The print_r($new_data)
will result in
Array(
[2015 - 07 - 018] => Array(
[sys_id] => 2015 - 07 - 018[account_id] => 2015 - 07 - 018[Names] => Array(
[0] => Array(
[fname] => Jackie[mname] => Lee[lname] => Chan[suffix] => Jr[city] => Tokyo[town] => Shinagawa - ku[dstrct] => District 2[street] => Jr[contactnum] => 1234)[1] => Array(
[fname] => Jackie[mname] => Lee[lname] => Chan[suffix] => Jr[city] => Tokyo[town] => Shinagawa - ku[dstrct] => District 2[street] => Jr[contactnum] => 1234)[2] => Array(
[fname] => Jackie[mname] => Lee[lname] => Chan[suffix] => Jr[city] => Tokyo[town] => Shinagawa - ku[dstrct] => District 2[street] => Jr[contactnum] => 1234)[3] => Array(
[fname] => Jackie[mname] => Lee[lname] => Chan[suffix] => Sr[city] => Tokyo[town] => Shinagawa - ku[dstrct] => District 2[street] => Sr[contactnum] => 1234)[4] => Array(
[fname] => Jackie[mname] => Lee[lname] => Chan[suffix] => Sr[city] => Tokyo[town] => Shinagawa - ku[dstrct] => District 2[street] => Sr[contactnum] => 1234)[5] => Array(
[fname] => Jackie[mname] => Lee[lname] => Chan[suffix] => Sr[city] => Tokyo[town] => Shinagawa - ku[dstrct] => District 2[street] => Sr[contactnum] => 1234))))
Update
I tried print_r($new_data1);
the result is exactly like the result of print_r($new_data);
Looking for a way to remove duplicate I found this
function super_unique($array) {
$result = array_map("unserialize", array_unique(array_map("serialize", $array)));
foreach($result as $key => $value) {
if (is_array($value)) {
$result[$key] = super_unique($value);
}
}
return $result;
}
The task i want to do now is to reindex the array because the output is
Array ( [1] => Array ( [sis_id] => 2015-07-018 [account_id] => 2015-07-018 [Names] => Array ( [0] => Array ( [fname] => Jackie [mname] => Lee [lname] => Chan [suffix] => Jr [city] => Tokyo [town] => Shinagawa-ku [brgy] => District 2 [contactnum] => 1234 ) [3] => Array ( [fname] => Jackie [mname] => Lee [lname] => Chan [suffix] => Sr [city] => Tokyo [town] => Shinagawa-ku [brgy] => District 2 [contactnum] => 1234 ) ) ) )
I want the old format for the out put