循环创建HTML元素 [英] Create HTML elements in loop

查看:120
本文介绍了循环创建HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个数字,例如:6我需要生成6个DIV元素.
例如:

Given a number like i.e: 6 I need to generate 6 DIV elements.
For example:

$number = 6;
// PHP generates the DIV for $number of times (6 in this case).

我该怎么办?如果是这种情况,我不是PHP循环专家.谢谢!

How can I do it? I am not an expert of PHP loops, if this is the case. Thanks!

推荐答案

可以使用的不同类型的循环的示例用法.希望您能看到它们的工作原理.

Example uses of the different types of loops you could use. Hopefully you can see how they work.

    $element = "<div></div>";
    $count = 6;
    foreach( range(1,$count) as $item){
        echo $element;
    }

循环时

   $element = "<div></div>";
   $count = 0;
   while($count < 6){
       $count++;
       echo $element;
   }

简单的循环

$element = "<div></div>"; 
$count = 6;
for ($i = 0; $i < $count; $i++) {
    echo $element;
}

这篇关于循环创建HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆