Php 需要根据数组中的内容停止和启动的foreach循环
目前,我的代码中有一个循环Php 需要根据数组中的内容停止和启动的foreach循环,php,arrays,loops,foreach,Php,Arrays,Loops,Foreach,目前,我的代码中有一个循环 <table width="100%" cellpadding="0" cellspacing="0" border="0"> <?php foreach($credits as $credit) : ?> <?php if($credit['credit_type'] == "short") : ?> <tr> <td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<?php foreach($credits as $credit) : ?>
<?php if($credit['credit_type'] == "short") : ?>
<tr>
<td><?php echo $credit['category_position']; ?></td>
<td><?php echo $credit['category_title']; ?></td>
</tr>
<tr>
<td><?php echo $credit['credit_heading']; ?></td>
<td><a href="">Edit</a></td>
</tr>
<?php endif; ?>
<?php if($credit['credit_type'] == "long") : ?>
<tr>
<td><?php echo $credit['category_position']; ?></td>
<td><?php echo $credit['category_title']; ?></td>
<td><strong>Title</strong></td>
<td><strong>Role</strong></td>
<td><strong>Director</strong></td>
</tr>
<tr>
<td><?php echo $credit['credit_position']; ?></td>
<td><?php echo $credit['credit_heading']; ?></td>
<td><?php echo $credit['credit_title']; ?></td>
<td><?php echo $credit['credit_role']; ?></td>
<td><?php echo $credit['credit_director']; ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
在IF语句中移动表标记
<?php foreach($credits as $credit) : ?>
<?php if($credit['credit_type'] == "short") : ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><?php echo $credit['category_position']; ?></td>
<td><?php echo $credit['category_title']; ?></td>
</tr>
<tr>
<td><?php echo $credit['credit_heading']; ?></td>
<td><a href="">Edit</a></td>
</tr>
</table>
<?php endif; ?>
<?php if($credit['credit_type'] == "long") : ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><?php echo $credit['category_position']; ?></td>
<td><?php echo $credit['category_title']; ?></td>
<td><strong>Title</strong></td>
<td><strong>Role</strong></td>
<td><strong>Director</strong></td>
</tr>
<tr>
<td><?php echo $credit['credit_position']; ?></td>
<td><?php echo $credit['credit_heading']; ?></td>
<td><?php echo $credit['credit_title']; ?></td>
<td><?php echo $credit['credit_role']; ?></td>
<td><?php echo $credit['credit_director']; ?></td>
</tr>
</table>
<?php endif; ?>
<?php endforeach; ?>
标题
角色
导演
注意只有当您只有2个
信用类型
值存储旧值,并且如果该值发生变化,则执行某些操作时,此操作才有效
foreach($array as $a) {
if($a != $oldvalue)
echo "end table, start table";
$oldvalue = $a;
}
是否只有两个不同的值?只有长或短的值short@ManseUK同意这是我将这样做,让另一个类别可以很容易地添加在未来。作为一个旁注,你能看到我的编辑吗?看看我有没有做错什么?
foreach($array as $a) {
if($a != $oldvalue)
echo "end table, start table";
$oldvalue = $a;
}