A
A
Alexander Toropov2019-01-06 14:12:28
PHP
Alexander Toropov, 2019-01-06 14:12:28

How to make another array from one array, but with grouping by element value?

Like from an array like this:

array (
  'NQ' => 'Комод',
  0 => 
  array (
    'Tr' => 'Вишня',
    'Ht' => 'значение',
    'HS' => 'значение',
    'AT' => 'значение',
  ),
  1 => 
  array (
    'Tr' => 'Вишня',
    'Ht' => 'значение2',
    'HS' => 'значение2',
    'AT' => 'значение2',
  ),
  2 => 
  array (
    'Tr' => 'Вишня',
    'Ht' => 'значение3',
    'HS' => 'значение3',
    'AT' => 'значение3',
    ),
  3 => 
  array (
    'Tr' => 'Бук',
    'Ht' => 'значение4',
    'HS' => 'значение4',
    'AT' => 'значение4',
  ),
  4 => 
  array (
    'Tr' => 'Бук',
    'Ht' => 'значение5',
    'HS' => 'значение5',
    'AT' => 'значение5',
  ),

do
array (
  'NQ' => 'Комод',
  'CL' => 'Вишня',
    0 => 
      array (
        'Ht' => 'значение',
        'HS' => 'значение',
        'AT' => 'значение',
  ),
    1 => 
      array (
      'Ht' => 'значение2',
      'HS' => 'значение2',
      'AT' => 'значение2',
  ),
    2 => 
      array (
        'Ht' => 'значение3',
        'HS' => 'значение3',
        'AT' => 'значение3',
    ),
  'CL' => 'Бук',
    0 => 
      array (
      'Ht' => 'значение4',
      'HS' => 'значение4',
      'AT' => 'значение4',
  ),
    1 => 
      array (
      'Ht' => 'значение5',
      'HS' => 'значение5',
      'AT' => 'значение5',
  ),

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2019-01-06
@alexey-m-ukolov

You brought an invalid structure as the desired result, so no way.

B
Beliyadm, 2019-01-06
@beliyadm

Ummm, there really is no way
Make a new array, where the first element will be Chest and the second is the first value of the nested array, the color and the nested elements will be old (that is, delete the first occurrence)
In the loop, iterate and collect a new array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question