I have a json response like below:
$response ='[
{
"userSummaries": [
{
"id": "9910",
"status": "Active",
"name": "Jhon"
}
]
},
{
"userSummaries": [
{
"id": "8754",
"status": "Active",
"name": "Jane"
}
]
}
]';
and I would like to group this by userSummaries with this php code:
$myArr = json_decode($response, true);
$result_arr = [];
array_walk($myArr,function($v,$k) use (&$result_arr){
$result_arr[key($v)] = $v[key($v)];
});
echo json_encode($result_arr);
and the response only return one data:
{"userSummaries":[{"id":"8754","status":"Active","name":"Jane"}]}
Is it possible to get the output response like this?:
{"userSummaries":[{"id":"9910","status":"Active","name":"Jhon"}, {"id":"8754","status":"Active","name":"Jane"}, ]}
Tried over the net but I did not found the solutions
here my script for this: https://3v4l.org/tVkK5
also tried this:
$class_array = array();
foreach ($myArr as $sa) {
$class_array[$sa['userSummaries']][] = array('name' => $sa['name']);
}
but return:
Notice: Undefined index: name in /in/hvSFC on line 28
Warning: Illegal offset type in /in/hvSFC on line 28
Notice: Undefined index: name in /in/hvSFC on line 28
Warning: Illegal offset type in /in/hvSFC on line 28
[]
need help