3v4l.org

run code in 300+ PHP versions simultaneously
<?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 );
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 0 => array ( 'product_id' => 101, 'name' => '', ), 1 => array ( 'product_id' => 201, 'name' => '', ), 2 => array ( 'product_id' => 301, 'name' => '', ), 3 => array ( 'product_id' => 102, 'name' => '', ), 4 => array ( 'product_id' => 202, 'name' => '', ), 5 => array ( 'product_id' => 302, 'name' => '', ), 6 => array ( 'product_id' => 103, 'name' => '', ), 7 => array ( 'product_id' => 303, 'name' => '', ), 8 => array ( 'product_id' => 304, 'name' => '', ), )
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')' in /in/J7Ggv on line 24
Process exited with code 255.
Output for 7.2.0 - 7.2.33
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')' in /in/J7Ggv on line 24
Process exited with code 255.

preferences:
83.74 ms | 409 KiB | 5 Q