У меня есть данные , которые выглядят так:
[{"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2005-03-27"},
{"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2005-04-13"},
{"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2006-06-07"},
{"REG":"SK", "RES":"PAN2", "WELL":"P2-TG", "TIME":"2009-01-18"},
{"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":"2009-03-01"},
{"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":"2010-03-14"}]
, и это мой код:
$query =[{my data}];
$list = [];
foreach($query as $index => $q){
if($index != 0){
$key = $index - 1;
$filter = [];
if($q->WELL == $query[$key]->WELL){
array_push($list,array_merge_recursive(json_decode(json_encode($q),true),json_decode(json_encode($query[$key]),true)));
}else{
array_push($list,$q);
}
}else{
array_push($list,$q);
}
}
мой результат после запуска по моему коду:
[{"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2005-03-27"},
{"REG":["SK","SK"], "RES":["PAN1","PAN1"], "WELL":["P1-TG","P1-TG"], "TIME":["2005-03-27","2005-04-13"]},
{"REG":["SK","SK"], "RES":["PAN1","PAN1"], "WELL":["P1-TG","P1-TG"], "TIME":["2005-04-13","2006-06-07"]},
{"REG":"SK", "RES":"PAN2", "WELL":"P2-TG", "TIME":"2009-01-18"},
{"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":"2009-03-01"},
{"REG":["SK","SK"], "RES":["PAN3","PAN3"], "WELL":["P3-TG","P3-TG"], "TIME":["2009-03-01","2010-03-14"]}]
и я хочу:
[{"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":["2005-03-27","2005-04-13","2006-06-07"]},
{"REG":"SK", "RES":"PAN2", "WELL":"P2-TG", "TIME":"2009-01-18"},
{"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":["2009-03-01","2010-03-14"]}]