$arr = [
[
"answer_schema_id" => "1",
"content" => "odpowiedz 1",
"locale" => "pl",
"points" => "3",
"answerKey" => "1",
"answerElementOrder" => "1",
"image" => "5cd143beba821203428009.jpg",
], [
"answer_schema_id" => "1",
"content" => "answer 1",
"locale" => "en",
"points" => "3",
"answerKey" => "1",
"answerElementOrder" => "1",
"image" => "5cd143beba821203428009.jpg",
], [
"answer_schema_id" => "2",
"content" => "answer 2",
"locale" => "en",
"points" => "2",
"answerKey" => "2",
"answerElementOrder" => "2",
"image" => "5cd143bebcdfc405126844.jpg",
], [
"answer_schema_id" => "2",
"content" => "odpowiedz 2",
"locale" => "pl",
"points" => "2",
"answerKey" => "2",
"answerElementOrder" => "2",
"image" => "5cd143bebcdfc405126844.jpg",
]
];
$result = [];
$ptr = [];
foreach ($arr as $el) {
if (!isset($ptr[$el['answer_schema_id']])) {
$res[] = [
"answer_schema_id" => $el['answer_schema_id'],
"content" => [],
"points" => $el['points'],
"answerKey" => $el['answerKey'],
"answerElementOrder" => $el['answerElementOrder'],
"image" => $el['image']
];
$ptr[$el['answer_schema_id']] = count($res)-1;
}
$res[$ptr[$el['answer_schema_id']]]['content'][$el['locale']] = $el['content'];
}
var_dump($res);
array(2) {
[0] => array(6) {
["answer_schema_id"] => string(1) "1"
["content"] => array(2) {
["pl"] => string(11) "odpowiedz 1"
["en"] =>string(8) "answer 1"
}
["points"] => string(1) "3"
["answerKey"] => string(1) "1"
["answerElementOrder"] => string(1) "1"
["image"] => string(26) "5cd143beba821203428009.jpg"
}
[1] => array(6) {
["answer_schema_id"] => string(1) "2"
["content"] => array(2) {
["en"] => string(8) "answer 2"
["pl"] => string(11) "odpowiedz 2"
}
["points"] => string(1) "2"
["answerKey"] => string(1) "2"
["answerElementOrder"] => string(1) "2"
["image"] => string(26) "5cd143bebcdfc405126844.jpg"
}
}