javascript - (remove duplicated) reindex multidimensional array php jquery -


[{     "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 result ajax request want remove duplicate result either server side or jquery side in server side have tried 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 $new_data result of select query. print_r($new_data) 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); result result of print_r($new_data);

looking way remove duplicate found this

function super_unique($array) { $result = array_map("unserialize", array_unique(array_map("serialize", $array))); foreach($result $key => $value) { if (is_array($value)) { $result[$key] = super_unique($value); } } return $result; }

the task want reindex array because output

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 old format out put

what if serialize each object in array string (json easiest in opinion) use native functions remove duplicates, unserialize objects?

sudo code this:

$serialized_array = []; foreach($new_data $data) {     $serialized_array[] = json_encode($data); }  $new_data = []; //reset new_data $unique = array_unique($serialized_array); foreach($serialized_array $string) {     $new_data[] = json_decode($string); } //new_data should contain unique data 

the main difference between you're doing , serializing , deserializing each object individually instead of entire array. key.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -