Answer the question
In order to leave comments, you need to log in
How to display a model grouped by one field?
There is a table "param"
| id | param_id | value |
| 1 | 50 | Title 1 |
| 2 | 50 | Title 2 |
| 3 | 50 | Title 3 |
| 4 | 555 | Title 4 |
| 5 | 555 | Title 5 |
| 6 | 555 | Title 6 |
The command Param::find()->asArray()->all();
outputs
Array
(
[0] => Array
(
[id] => 1
[param_id] => 50
[value] => Название 1
)
[1] => Array
(
[id] => 2
[param_id] => 50
[value] => Название 2
)
[2] => Array
(
[id] => 3
[param_id] => 50
[value] => Название 3
)
[3] => Array
(
[id] => 4
[param_id] => 555
[value] => Название 4
)
[4] => Array
(
[id] => 5
[param_id] => 555
[value] => Название 5
)
[5] => Array
(
[id] => 6
[param_id] => 555
[value] => Название 6
)
)
Array
(
[55] => Array
(
[0] => Array
(
[id] => 1
[param_id] => 50
[value] => Название 1
)
[1] => Array
(
[id] => 2
[param_id] => 50
[value] => Название 2
)
[2] => Array
(
[id] => 3
[param_id] => 50
[value] => Название 3
)
)
[555] => Array
(
[0] => Array
(
[id] => 4
[param_id] => 555
[value] => Название 4
)
[1] => Array
(
[id] => 5
[param_id] => 555
[value] => Название 5
)
[2] => Array
(
[id] => 6
[param_id] => 555
[value] => Название 6
)
)
)
Param::find()->groupBy('param_id')->asArray()->all();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question