<?php
$rows = [
100 => [
['product_id' => 101, 'name' => ''],
['product_id' => 102, 'name' => ''],
['product_id' => 103, 'name' => ''],
],
200 => [
['product_id' => 201, 'name' => ''],
['product_id' => 202, 'name' => ''],
],
300 => [
['product_id' => 301, 'name' => ''],
['product_id' => 302, 'name' => ''],
['product_id' => 303, 'name' => ''],
['product_id' => 304, 'name' => ''],
]
];
var_export(
array_merge( #flatten the unpacked elements
...array_map( #unpack
fn(...$v) => array_filter($v), #transpose discarding nulls
...$rows #transpose discarding nulls
) #unpack
) #flatten the unpacked elements
);
preferences:
60.4 ms | 407 KiB | 5 Q