I ask for help, I can not think of it!
I have a table in the database.
Here is a structure. Each record has a param field, there is a number from 1 to 4, based on this number I need to sort all the records by 4. A total of 26 items in the table:
[ 0 => app\models\Paramdoor#1 ( [yii\db\BaseActiveRecord:_attributes] => [ 'id' => 1 'name' => 'Стандарт' 'price' => '' 'param' => 1 'content' => 'Коробочный брус' 'disabled' => 1 ] ) 1 => app\models\Paramdoor#2 ( [yii\db\BaseActiveRecord:_attributes] => [ 'id' => 2 'name' => '1 комплект' 'price' => '601 грн' 'param' => 1 'content' => 'Коробочный брус Стандарт' 'disabled' => 0 ] ) I create 4 empty arrays:
$arr1 = array(); $arr2 = array(); $arr3 = array(); $arr4 = array(); As I understand through foreach I run a multidimensional array:
foreach ($params as $param=>$row) { if($row[param]==1){ $arr1[]=$row; } else if($row[param]==2){ $arr2[]=$row; } else if($row[param]==3){ $arr3[]=$row; } else if($row[param]==4){ $arr4[]=$row; } } And so I get 4 different arrays for each <select> .
What is of interest - is there a more elegant way?
$paramArr[$row[$param]][]=$row- zb '${"arr" . $row["param"]}[] = $row;${"arr" . $row["param"]}[] = $row;- Serge Seredenko