당신은이 경우, 경우는 항상 바구니 라인의 최대 수를 알고하는 foreach
대신 for
루프를 사용하여 형편이 아마 더 좋을 것 같아 라인 1-7에 일치하는 바스켓 라인이 있습니다. 그렇지 않은 경우 - 공란으로 인쇄하십시오.
<?php
/**
* Loop through each $items
* line of the basket as $lines[1] .. $lines[2]..
**/
for ($x = 0; $x <= 7; $x++) {
//Does this basket line have an item?
$hasLine = (isset($items[$x]) ? true : false); ?>
<tr>
<td><?php echo ($hasLine ? $items[$x]->item_name : ''); ?></td>
<td><?php echo ($hasLine ? $items[$x]->item_description : ''); ?></td>
<td><?php echo ($hasLine ? $items[$x]->item_quantity : ''); ?></td>
<td><?php echo ($hasLine ? $items[$x]->item_subtotal : ''); ?></td>
</tr>
<?php } ?>
비록
, 당신은 항상 비어 있거나하지 않은 경우에 관계없이 최대 수 송장 행을 보유하고 변수와 숫자 7을 대체 할 수 있습니다.
$invoiceLines = 7;
for ($x = 0; $x <= $invoiceLines; $x++) {
//Code.
}
내 질문을 수정하고 대답 해 주셔서 고맙습니다. – user2815020
귀하의 환영합니다! =) – MackieeE