简单介绍:把一个数组分成4个数组,取其中1的倍数
<?php
$arr = array(
'' => '',
'' => '',
'' => '',
'' => '', '' => '',
'' => '',
'' => '',
'' => '', '' => '',
'' => '',
'' => '',
'' => '', '' => '', );
foreach($arr as $k=>$val){
for($i=0;$i<4;$i++){
$a = $i*4+1; // 其中的1是倍数,可以是0、1、2、3不能超过4;如果是7,则$i<7;
if($k==$a){
$item[] = $val;
}
}
}
?> 输出结果
Array ( [0] => 1 [1] => 5 [2] => 9 );
简单介绍:把一个数组分成4个数组,取其中3的倍数
<?php
$arr = array(
'' => '',
'' => '',
'' => '',
'' => '', '' => '',
'' => '',
'' => '',
'' => '', '' => '',
'' => '',
'' => '',
'' => '', '' => '', );
foreach($arr as $k=>$val){
for($i=;$i<;$i++){
$a = $i*+; // 其中的1是倍数,可以是0、1、2、3不能超过4;如果是7,则$i<7;
if($k==$a){
$item[] = $val;
}
}
}
?> 输出结果
Array ( [0] => 3 [1] => 7 [2] => 11 )
与数据库结合
class IndexAction extends BaseAction
{
public function index()
{ $m = M('article');
$res = $m->select();
$f = $this->d($res,);
print_r($f); } public function d($arr,$v){
foreach($arr as $k=>$val){
for($i=;$i<;$i++){
$a = $i*+$v;
if($k==$a){
$item[] = $val;
}
}
}
return $item; } } 输出结果
Array ( [0] => Array ( [id] => 3 [catid] => 1 [userid] => 1 [username] => yourphp [title] => 欧美风2014夏新款韩国名媛精致复合提花拼纱荷叶袖连衣裙 [title_style] => [keywords] => [copyfrom] => [fromlink] => [description] => 欧美风2014夏新款韩国名媛精致复合提花拼纱荷叶袖连衣裙 [content] => 欧美风2014夏新款韩国名媛精致复合提花拼纱荷叶袖连衣裙 [template] => 0 [thumb] => /b/Uploads/201407/53d220e49655a.jpg [posid] => 0 [status] => 1 [recommend] => 1 [readgroup] => [readpoint] => 0 [listorder] => 0 [url] => /b/index.php?m=Article&a=show&id=3 [hits] => 0 [createtime] => 1406279913 [updatetime] => 1406279913 [name] => [lang] => 1 ) )
实例分析:瀑布流
<div>
<ul>
<!--第一列-->
<li></li>
<!--第二列-->
<li></li>
<!--第三列-->
<li></li>
<!--第四列-->
<li></li>
</ul>
</div>
html代码
<!-- screeenA瀑布流 -->
<div class="screenA">
<ul>
<li>
<volist name="arr_0" id="vo">
<div class="ka">
<div class="im">
<img src="{$vo.thumb}" />
</div>
<div class="text"><a href="{$vo.url}">{$vo.title}</a></div>
<div class="t_bot"><div class="zan" style="float:left"><span>赞 </span></div><div class="liulan">浏览()</div></div>
<div class="line"></div>
<div class="ask">
<div class="ask_left"><img src="../Public/images/ico_03.jpg" /></div>
<div class="ask_rig"><h3>星空下的骑士</h3><span>连体短裤是夏季最凉快和轻便的着装,简单风格</span></div>
<div class="clear"></div>
</div>
</div>
</volist>
</li>
<li>
<volist name="arr_1" id="vo">
<div class="ka">
<div class="im">
<img src="{$vo.thumb}" />
</div>
<div class="text"><a href="{$vo.url}">{$vo.title}</a></div>
<div class="t_bot"><div class="zan" style="float:left"><span>赞 </span></div><div class="liulan">浏览()</div></div>
<div class="line"></div>
<div class="ask">
<div class="ask_left"><img src="../Public/images/ico_03.jpg" /></div>
<div class="ask_rig"><h3>星空下的骑士</h3><span>连体短裤是夏季最凉快和轻便的着装,简单风格</span></div>
<div class="clear"></div>
</div>
</div>
</volist>
</li>
<li>
<volist name="arr_2" id="vo">
<div class="ka">
<div class="im">
<img src="{$vo.thumb}" />
</div>
<div class="text"><a href="{$vo.url}">{$vo.title}</a></div>
<div class="t_bot"><div class="zan" style="float:left"><span>赞 </span></div><div class="liulan">浏览()</div></div>
<div class="line"></div>
<div class="ask">
<div class="ask_left"><img src="../Public/images/ico_03.jpg" /></div>
<div class="ask_rig"><h3>星空下的骑士</h3><span>连体短裤是夏季最凉快和轻便的着装,简单风格</span></div>
<div class="clear"></div>
</div>
</div>
</volist>
</li>
<li>
<volist name="arr_3" id="vo">
<div class="ka">
<div class="im">
<img src="{$vo.thumb}" />
</div>
<div class="text"><a href="{$vo.url}">{$vo.title}</a></div>
<div class="t_bot"><div class="zan" style="float:left"><span>赞 </span></div><div class="liulan">浏览()</div></div>
<div class="line"></div>
<div class="ask">
<div class="ask_left"><img src="../Public/images/ico_03.jpg" /></div>
<div class="ask_rig"><h3>星空下的骑士</h3><span>连体短裤是夏季最凉快和轻便的着装,简单风格</span></div>
<div class="clear"></div>
</div>
</div>
</volist>
</li>
<div class="clear"></div>
</ul>
</div>
<!-- screeenA瀑布流End -->
php代码
class IndexAction extends BaseAction
{
public function index()
{ $m = M('article');
$res = $m->select();
//print_r($item); $arr[] = $this->falls($res,);
$arr[] = $this->falls($res,);
$arr[] = $this->falls($res,);
$arr[] = $this->falls($res,); $this->assign('bcid',);//顶级栏目
$this->assign('arr_0',$this->falls($res,));
$this->assign('arr_1',$this->falls($res,));
$this->assign('arr_2',$this->falls($res,));
$this->assign('arr_3',$this->falls($res,));
$this->assign('ishome','home');
$this->display();
} public function falls($arr,$v){
foreach($arr as $k=>$val){
for($i=;$i<;$i++){
$a = $i*+$v;
if($k==$a){
$item[] = $val;
}
}
}
return $item; } }