前提・実現したいこと
Laravelで体育館の利用状況のシステムを作っていて
各体育館の住所で重複している場合はセルを結合したいです。
▼理想のアウトプット
<table> <thead> <tr> <th>校舎住所1</th> <th>校舎住所2</th> </tr> </thead> <tbody> <tr> <td rowspan="3">大阪</td> <td>123-14</td> </tr> <tr> <td>123-15</td> </tr> <tr> <td>123-16</td> </tr> <tr> <td>長崎</td> <td>123-14</td> </tr> <tr> <td rowspan="2">沖縄</td> <td>123-14</td> </tr> <tr> <td>123-15</td> </tr> </tbody> </table>
foreachで前回の校舎住所1が同じ場合はrowspan用のデータを加えたいのですが
ひとつ前の比較しかできず、困っています。
どなたか解決方法ご存知の方いましたら教えていただけますと幸いです。
▼これだと3件以上の重複に対応できていない。。
$temp = "A"; foreach($schools as $key => $school){ if($school->school_location1 == $temp){ $schools[$key-1]->school->school_count++; } $temp = $school->school->school_location1; }
▼元データ
App\School Object ( [attributes:protected] => Array ( [school_location1] => 大阪 [school_location2] => 123-14 ) [original:protected] => Array ( [school_location1] => 大阪 [school_location2] => 123-14 ) ) App\School Object ( [attributes:protected] => Array ( [school_location1] => 大阪 [school_location2] => 123-15 ) [original:protected] => Array ( [school_location1] => 大阪 [school_location2] => 123-15 ) ) App\School Object ( [attributes:protected] => Array ( [school_location1] => 大阪 [school_location2] => 123-16 ) [original:protected] => Array ( [school_location1] => 大阪 [school_location2] => 123-16 ) ) App\School Object ( [attributes:protected] => Array ( [school_location1] => 長崎 [school_location2] => 123-14 ) [original:protected] => Array ( [school_location1] => 長崎 [school_location2] => 123-14 ) ) App\School Object ( [attributes:protected] => Array ( [school_location1] => 沖縄 [school_location2] => 123-14 ) [original:protected] => Array ( [school_location1] => 沖縄 [school_location2] => 123-14 ) ) App\School Object ( [attributes:protected] => Array ( [school_location1] => 沖縄 [school_location2] => 123-15 ) [original:protected] => Array ( [school_location1] => 沖縄 [school_location2] => 123-15 ) )
回答1件
あなたの回答
tips
プレビュー