我正在尝试将一些信息从数据库流入 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'] 以便在下一次迭代开始时重新使用,这不会发生。我错过了什么吗?