3v4l.org

run code in 300+ PHP versions simultaneously
<?php $collections = [ 0 => [ 0 => [ "attr_id" => 23, "value" => "Single Side" ], 1 => [ "attr_id" => 23, "value" => "Double Side" ], ], 1 => [ 0 => [ "attr_id" => 31, "value" => "A4" ], 1 => [ "attr_id" => 31, "value" => "12x18" ], 2 => [ "attr_id" => 31, "value" => "B5" ], 3 => [ "attr_id" => 31, "value" => "A5" ] ] ]; $expected = []; foreach($collections as $k=>$v){ foreach($v as $k1=>$v1){ $expected[$v1['attr_id']][] = $v1['value']; } } print_r($expected) ?>

preferences:
42.78 ms | 1690 KiB | 5 Q