Showing
1 changed file
with
6 additions
and
4 deletions
@@ -153,16 +153,18 @@ EOL; | @@ -153,16 +153,18 @@ EOL; | ||
153 | $banners = $this->view->rightBanners; | 153 | $banners = $this->view->rightBanners; |
154 | $temp = array(); | 154 | $temp = array(); |
155 | $len = count($banners); | 155 | $len = count($banners); |
156 | - if($len >=3) | 156 | + if($len >3 && is_numeric($len)&(!($len&1))) |
157 | { | 157 | { |
158 | //随机选择出两个元素 | 158 | //随机选择出两个元素 |
159 | $temp=array_rand($banners,2); | 159 | $temp=array_rand($banners,2); |
160 | foreach($temp as $val){ | 160 | foreach($temp as $val){ |
161 | $data_last[]=$banners[$val]; | 161 | $data_last[]=$banners[$val]; |
162 | } | 162 | } |
163 | -// $temp = array_slice($banners, 0,1); | ||
164 | -// $pos = rand(1, $len-1); | ||
165 | -// $banners = array_merge($temp, array_slice($banners, $pos, 2)); | 163 | + } |
164 | + if($len >=3 && is_numeric($len)&($len&1)){ | ||
165 | + $temp = array_slice($banners, 0,1); | ||
166 | + $pos = rand(1, $len-1); | ||
167 | + $data_last = array_merge($temp, array_slice($banners, $pos, 1)); | ||
166 | } | 168 | } |
167 | foreach($data_last as $banner): | 169 | foreach($data_last as $banner): |
168 | $res_size = json_decode($banner['res_size'], true); | 170 | $res_size = json_decode($banner['res_size'], true); |
-
Please register or login to post a comment