データベースからHTMLに情報を流して、ユーザーに表示しようとしています。「業界」が変わるたびに新しいタグを印刷したいのですが。$ last_industryという変数を使用して、現在反復している業界が最後の業界と等しいかどうかを追跡しようとしていますが、良い結果が得られていません。以下にコードを貼り付けました。$c['user_industries_title']は私が監視する必要があるものです。
$last_industry = 'foo';
foreach($case_studies as &$c) {
//If the last industry we iterated over is different than the one we're currently iterating over, close the last section and print a new section.
if($last_industry != $c['user_industries_title']){
echo "</section>"
echo "<section>";
$changed = 1;
}else {$changed = 0}
$c = $last_industry;
$last_industry = $c['user_industries_title'];
}
この問題は、$last_industry変数にあります。これを機能させるには、次の反復の開始時に使用できるように、最新の$c['user_industries_title']に更新する必要があります。これは発生していません。私は何かが足りないのですか?