今天工作中碰到一个需要是先查指定数据库中是不是有满足条件的6条数据,如果没有再从B表中查找 6-A表中的数据之后再进行数组合并了,下面我来把我们整个过程给各位分享一下。
<script>ec(2);</script>
在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
{
$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()合并时我们必须要注意一点的是中间的值必须为数组否则合并之后会返回空哦,这个我们经验哦。