基本上我想創造的東西,讓我做這件事:如何在PHP中創建分段的foreach()函數?
<?php
function herp(){foreach($users as $user):}
function derp(){endforeach;}
?>
<html><body>
<?php herp();?>
<?php $user->name();?>,<?php $user->name();?>,<?php $user->name();?>
<?php derp();?>
</body></html>
--------- output ---------
John Doe, 1900, Buttery Yellow
Jane Doe, 1900, Platypus Brown
我不想創建或依賴模板引擎。我只是想讓它創建頁面模板的人可以爲他提供循環。
'make'絕對不是一個恰當的標籤! –
結帳[小鬍子](http://mustache.github.com/) - https://github.com/bobthecow/mustache.php – hakre
你不能像這樣分割出一個'foreach','endforeach'就是預計將在相同的範圍內。 – CodeCaster