<?php
$arrays = [
[
"id" => 1,
"order_id" => 1,
"image_url" => "/resources/filename1"
],
[
"id" => 2,
"order_id" => 1,
"image_url" => "/resources/filename2"
],
[
"id" => 3,
"order_id" => 1,
"image_url" => "/resources/filename3"
],
[
"id" => 4,
"order_id" => 2,
"image_url" => "/resources/filename4"
],
];
foreach($arrays as $array) {
if(!isset($result[$array['order_id']]['id'])) {
$result[$array['order_id']]['id']=$array['id'];
}
$result[$array['order_id']]['order_id']=$array['order_id'];
$result[$array['order_id']]['image_url'][]=$array['image_url'];
}
print_r($result);
preferences:
58.79 ms | 404 KiB | 5 Q