首页 > php教程 > php手册 > 正文

数组循环:循环多个li 每个li 固定N条数据,li

WBOY
发布: 2016-06-13 08:47:43
原创
964 人浏览过

数组循环:循环多个li 每个li 固定N条数据,li

PHP代码:

   <span>$arr</span> = <span>array</span>(1,2,3,4,5,6,7<span>); 
  </span><span>$x</span> = 1<span>;
    </span><span>$y</span> = 0<span>;
    </span><span>foreach</span>(<span>$arr</span> <span>as</span> <span>$k</span> => <span>$v</span><span>){
        </span><span>$data</span>[<span>$y</span>][] = <span>$v</span><span>;
     </span><span>//</span><span>4 就是没个li显示4条数据,如果显示3条,改成3即可。</span>
        <span>if</span>(<span>$x</span> == 4<span>){
            </span><span>$y</span>++<span>;
            </span><span>$x</span>=1<span>;
            </span><span>continue</span><span>;
        }
        </span><span>$x</span>++<span>;
    }

  </span><span>//</span><span>$data  是最终的结果集,发送到页面循环即可.</span>
登录后复制

HTML代码(我这里是smarty模板):

<span><</span><span>ul</span><span>></span><span>   
    {foreach from=$data item=vo}
        </span><span><</span><span>li</span><span>></span><span>
            {foreach from=$vo item=val}
                </span><span><</span><span>a </span><span>href</span><span>="#"</span><span>><</span><span>img </span><span>src</span><span>="{$val.xxxx}"</span><span>></</span><span>a</span><span>></span><span>
            {/foreach}
        </span><span></</span><span>li</span><span>></span><span>
    {/foreach}
</span><span></</span><span>ul</span><span>></span>
登录后复制

结果:

· 1234
·567

 

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板