I have the following arrays :

```
Array ( 
    [0] => Array ( 
        [id] => 1 
        [name] => Apple
        [type] => Fruit 
    ) 
    [1] => Array ( 
        [id] => 3 
        [name] => Chanterelles
        [type] => Vegetable
    ) 
    [2] => Array ( 
        [id] => 4 
        [name] => Lenses
        [type] => Legume
    ) 
    [3] => Array ( 
        [id] => 2 
        [name] => Banana
        [type] => Fruit
    ) 
    [4] => Array ( 
        [id] => 5 
        [name] => Rocket
        [type] => Vegetable
    ) 
)

```

My expected ouput :

```
Array (
    [Fruit] => Array (
        Array (
            [id] => 1 
            [name] => Apple
        )
        Array (
            [id] => 2
            [name] => Banana
        )
    )
    [Vegetable] => Array (
        Array (
            [id] => 3
            [name] => Chanterelles
        )
        Array (
            [id] => 5
            [name] => Rocket
        )
    )
    [Legume] => Array (
        Array (
            [id] => 4
            [name] => Lenses
        )
    )
)

```

My initial array :

```
var_dump(array(
    array(
        'id' => 1,
        'name' => 'Apple',
        'type' => 'Fruit'
    ),
    array(
        'id' => 3,
        'name' => 'Chanterelles',
        'type' => 'Vegetable'
    ),
    array(
        'id' => 4,
        'name' => 'Lenses',
        'type' => 'Legume'
    ),
    array(
        'id' => 2,
        'name' => 'Banana',
        'type' => 'Fruit'
    ),
    array(
        'id' => 5,
        'name' => 'Rocket',
        'type' => 'Vegetable'
    )
));

```

I tried the following :

```
foreach($myarray as $ingredient){
    $type_arr[] = $ingredient['type'];
}
$type_arr_uq = array_unique($type_arr);
$new_arr = array();
foreach($type_arr_uq as $type){
  foreach($myarray as $ingredient){
      if($type == $ingredient['type']){
          $new_arr[$type] = ['id' => $ingredient['id'], 'name' => $ingredient['name']];
      }
    }
}

```

Output:

```
Array
(
    [Fruit] => Array
        (
            [id] => 2
            [name] => Banana
        )

    [Vegetable] => Array
        (
            [id] => 5
            [name] => Rocket
        )

    [Legume] => Array
        (
            [id] => 4
            [name] => Lenses
        )

)

```

Demo: <http://sandbox.onlinephpfunctions.com/code/4886faa73b56b62fdf954f06e902f1d0bd301a71>