给定一个数字,例如:6
我需要生成6个DIV
元素。
例如:
$number = 6;
// PHP generates the DIV for $number of times (6 in this case).
我该怎么做?如果是这种情况,我不是 PHP 循环专家。谢谢!
您可以使用的不同类型循环的示例用途。希望您能看到它们是如何工作的。
Foreach循环
$element = "<div></div>";
$count = 6;
foreach( range(1,$count) as $item){
echo $element;
}
While 循环
$element = "<div></div>";
$count = 0;
while($count < 6){
$count++;
echo $element;
}
简单的 For 循环
$element = "<div></div>";
$count = 6;
for ($i = 0; $i < $count; $i++) {
echo $element;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)