在php中合并数组我们可以使用array_merge函数
array array_merge (array array1 array2…,arrayN)
例子
代码如下 |
复制代码 |
//团购1
$t=1;
$tugou = esf(" * "," setindex='1' $cwhere order by id desc limit 0,6","A表");
foreach( $tugou as $v =>$_v )
{
$tugou[$v]['i'] =$t++;
}
$abpccount = count( $tugou );
//echo $abpccount;
if( $abpccount < 6 )
{
$page->tpl->assign('notg',1);//调用团购标签
$abpclimit = 6 - $abpccount;
$tugou_loupan = esf(" * "," index_dt='1' $cwhere order by id desc limit 0,$abpclimit ","B表");
foreach( $tugou_loupan as $v =>$_v )
{
$tugou_loupan[$v]['i'] =$t++;
$tugou_loupan[$v]['abpcindexpic'] = $_v['abpcthumb'];
$tugou_loupan[$v]['abpclitpic'] = $_v['abpcthumb'];
$tugou_loupan[$v]['abpcname'] = mt_rand(10,80);
$tugou_loupan[$v]['abpcdown'] = 'xx 惠';
$tugou_loupan[$v]['abpclpname'] = $_v['abpcname'];
}
$tugou = array_merge($tugou,$tugou_loupan);
}
$page->tpl->assign('tugou',$tugou);
|
注意事项
array_merge()合并时我们必须要注意一点的是中间的值必须为数组否则合并之后会返回空哦,这个我们经验哦。