因应不同的组合但又必须要补齐
所以有三种选择
状况 1. 当产品大于组合 2. 当产品可整除组合 3.当产品小于组合
<?php
class 广告插入处理
{
public $阵列;
public $每组数;
function 阵列组数($阵列,$每组数)
{
$this->阵列=$阵列;
$this->每组数=$每组数;
}
function 大于或小于()
{
$总数=count($this->阵列);
if(is_int($总数/$this->每组数)){return '等于';}
if($总数 > $this->每组数){return '大于';}
if($总数 == $this->每组数){return '等于';}
if($总数 < $this->每组数){return '小于';}
}
function 分组数量判断()
{
$大于或小于= $this-> 大于或小于();
$总数=count($this->阵列);
$取整数 = floor(round($总数/$this->每组数,1));
$取小数 = round($总数/$this->每组数,1)-$取整数;
switch ($大于或小于)
{
case '大于':
echo $大于或小于;
$补码量 = $this->每组数-floatval($this->每组数 *$取小数);
for ($a = 0; $a < $补码量; $a++)
{
array_push($this->阵列, "广告");
}
shuffle($this->阵列); // 乱排阵列
print_r($this->阵列);
break;
case '等于':
echo $大于或小于;
print_r($this->阵列);
break;
case '小于':
echo $大于或小于;
$补码量 = $this->每组数-$总数;
for ($a = 0; $a < $补码量; $a++)
{
array_push($this->阵列, "广告");
}
shuffle($this->阵列); // 乱排阵列
print_r($this->阵列);
break;
}}}
$广告插入处理 = new 广告插入处理();
$阵列=["a","b","c","d","e","f"];
$每组数 = 5;
$广告插入处理-> 阵列组数($阵列,$每组数);
echo $广告插入处理-> 分组数量判断();