php - Hash/array compare and merge -
i have 2 info sets.
first:
{ "status": "ok", "message": "data show successful", "name0": "al", "city": "", "pree": "r", "allknife": [ { "name": "folder", "pos": "g", "pos_le": "", }, { "name": "folder two", "pos": "g", "pos_le": "", } ] }
second:
{ "status": "ok", "message": "data show successful", "name0": "", "city": "", "pree": "r", "allknife": [ { "name": "folder", "pos": "", "pos_le": "r", }, { "name": "folder two", "pos": "g", "pos_le": "", } ] }
now compare sec info set first info set. if item empty in sec info set, want pulled first info set.
for instance, in sec hash name0
empty value should replaced using value first hash. allknife
array should utilize same logic.
i cant understand how implement it. trying array_merge(), no avail.
there lot of things might optimized leave you!
// simple illustration function arfill($example, $input){ foreach($input $key => $value){ if($value == ""){ // easy peasy set $input[$key] = $example[$key]; } if(is_array($value)){ // little recursion here $input[$key] = arfill($example[$key], $input[$key]); } } homecoming $input; }
php arrays
No comments:
Post a Comment