$test = $collect
->groupBy('product')->map(function ($item) {
return $item[0];
})->toArray();
$test_2 = $collect_2
->groupBy('product')->map(function ($item) {
return $item[0];
})->toArray();
foreach ($test as $key => $item) {
$test_3[$key] = array_merge($test[$key] ?? [], $test_2[$key] ?? []);
}
$localKeys = array_column($arr1, 'product');
$remoteKeys = array_column($arr2, 'product');
$totalKeys = array_values(array_unique(array_merge($localKeys, $remoteKeys)));
$localLinks = array_combine(
$localKeys,
array_column($arr1, 'local_link')
);
$remoteLinks = array_combine(
$remoteKeys,
array_columns($arr2, 'remote_link')
);
$result = array_map(
fn($key) => [
'product' => $key,
'local_link' => $localLinks[$key] ?? null,
'remote_link' => $remoteLinks[$key] ?? null
]
);
<div class="wrapper">
<div class="item"></div>
...
<div class="item"></div>
</div>
.item {
min-height: 250px;
}
.item:nth-child(n+10) {
min-height: 30px;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, minmax(250px, auto)) minmax(30px, auto);
}