Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
$products = [ '0' => [ 'category-id' => '...' 'name' => '...' ] '1' => [ 'category-id' => '...' 'name' => '...' ] и т.д. ]
Или может есть такой SQL запрос?
$grouped = []; foreach ($products as $p) { $grouped[$p['category-id']][] = $p['name']; }
$grouped = []; foreach ($products as $p) { $grouped[$p['category-id']][] = $p['name']; $grouped[$p['category-id']][] = $p['price']; }
array([0] => [name1], [1] => [price1], [2] => [name2], [3] => [price2])
array([0] => array([0] => [name1] [1] => [price1]) [1] => array([0] => [name2] [1] => [price2])
$grouped = []; foreach ($products as $p) { $id = $p['category-id']; unset($p['category-id']); $grouped[$id][] = array_values($p); }