时间:2021-07-01 10:21:17 帮助过:22人阅读
PHP代码:
$arr = array(1,2,3,4,5,6,7); $x = 1; $y = 0; foreach($arr as $k => $v){ $data[$y][] = $v; //4 就是没个li显示4条数据,如果显示3条,改成3即可。 if($x == 4){ $y++; $x=1; continue; } $x++; } //$data 是最终的结果集,发送到页面循环即可.
HTML代码(我这里是smarty模板):
<ul> {foreach from=$data item=vo} <li> {foreach from=$vo item=val} <a href="#"><img src="{$val.xxxx}">a> {/foreach} li> {/foreach} ul>
结果:
· 1234
·567
http://www.bkjia.com/PHPjc/1091266.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1091266.htmlTechArticle数组循环:循环多个li 每个li 固定N条数据,li PHP代码: $arr = array (1,2,3,4,5,6,7 ); $x = 1 ; $y = 0 ; foreach ( $arr as $k = $v ){ $data [ $y ][] = $v ; // 4 就...