本文介紹了帶有 HTML 的 PHP 簡單 foreach 循環(huán)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想知道實際編寫以下內容是否效果最好,例如:
I am wondering if it will work best to actually write the following for example:
<table>
<?php foreach($array as $key=>$value){ ?>
<tr>
<td><?php echo $key; ?></td>
</tr>
<?php } ?>
</table>
所以基本上是在 foreach 循環(huán)中嵌入 HTML,但不使用 echo
打印表格標簽.這會奏效嗎?我知道在 JSP 中這是有效的.
So basically embedding HTML inside foreach loop but without using echo
to print the table tags. Will this work? I know in JSP this works.
推薦答案
雖然在 HTML 中嵌入 PHP 時最好使用以下形式,但這種方法會起作用:
This will work although when embedding PHP in HTML it is better practice to use the following form:
<table>
<?php foreach($array as $key=>$value): ?>
<tr>
<td><?= $key; ?></td>
</tr>
<?php endforeach; ?>
</table>
您可以找到有關 PHP 替代語法的文檔.凈
這篇關于帶有 HTML 的 PHP 簡單 foreach 循環(huán)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!