PHP: <div class="print"> <?php foreach ($models as $model):?> <?php if ($clubId !== $model->profile->club_id):?> <?php if ($model->profile->club_id):?><span>Коллектив: <strong><?=$formatter->asText($clubName = $model->profile->club->name)?></strong></span><?endif;?> <?php if ($model->profile->city_id):?><span>Город: <strong><?=$formatter->asText($model->profile->city->name)?></strong></span><?endif;?> <?php if ($model->profile->club_id):?><span>Руководитель: <strong><?=$formatter->asText($model->profile->club->chiefId1->getFullName())?></strong></span><?endif;?> <? endif; ?> <?php if ($userId !== $model->user_id):?> <h4><?=$model->profile->getFullName()?></h4> <? endif; ?> <table class="table table-bordered table-payment"> <thead> <tr class="table-head"> <td>№ участника</td> <td>Ранг</td> <td>Дисциплина</td> <td>Номинация</td> <td>Возрастная категория</td> <td>Композиция</td> <td>Взнос</td> </tr> </thead> <tbody> <tr class="table-body"> <td><?=$formatter->asInteger($model->number)?></td> <td><?=$formatter->asText($model->rang->getShortName())?></td> <td><?=$formatter->asText($model->discipline->getShortName())?></td> <td><?=$formatter->asText($model->nomination->getShortName())?></td> <td><?=$formatter->asText($model->category->getShortName())?></td> <td><?=$formatter->asText($model->music?$model->music->composition_name:null)?></td> <?php if ($model->price):?><td><?=$formatter->asText($model->price->cost)?></td><?else:?><td>—</td><?endif;?> </tr> </tbody> </table> <?php $clubId = $model->profile->club_id; $userId = $model->user_id; ?> <?php endforeach;?> </div> Мне нужно объединить по пользователю <tbody>
PHP: <div class="print"> <?php $m = array(); foreach ($models as $model) { $shapka = ''; if ($clubId !== $model->profile->club_id) { if ($model->profile->club_id) $shapka.= '<span>Коллектив: <strong>'. $formatter->asText($clubName = $model->profile->club->name).'</strong></span>'; if ($model->profile->city_id) $shapka.= '<span>Город: <strong>'. $formatter->asText($model->profile->city->name).'</strong></span>'; if ($model->profile->club_id) $shapka.= '<span>Руководитель: <strong>'. $formatter->asText($model->profile->club->chiefId1->getFullName()).'</strong></span>'; }; if ($userId !== $model->user_id) $shapka.= '<h4>'.$model->profile->getFullName().'</h4>'; $stroka = ' <tr class="table-body"> <td>'.$formatter->asInteger($model->number).'</td> <td>'.$formatter->asText($model->rang->getShortName()).'</td> <td>'.$formatter->asText($model->discipline->getShortName()).'</td> <td>'.$formatter->asText($model->nomination->getShortName()).'</td> <td>'.$formatter->asText($model->category->getShortName()).'</td> <td>'.$formatter->asText($model->music?$model->music->composition_name:null).'</td> '; if ($model->price) $stroka.='<td>'.$formatter->asText($model->price->cost).'</td>'; else $stroka.='<td>—</td>'; $clubId = $model->profile->club_id; $userId = $model->user_id; if (!isset($m[$userId])) $m[$userId]=array($shapka); $m[$userId][] = $stroka; } foreach ($m as $userId=>$stroki) { echo array_shift($stroki); echo ' <table class="table table-bordered table-payment"> <thead> <tr class="table-head"> <td>№ участника</td> <td>Ранг</td> <td>Дисциплина</td> <td>Номинация</td> <td>Возрастная категория</td> <td>Композиция</td> <td>Взнос</td> </tr> </thead> <tbody>'; foreach ($stroki as $e) echo $e; echo ' </tbody> </table>'; };?> </div>