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) ?>

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
158.66 ms | 2312 KiB | 9 Q