阵列分组,不足数,补足

因应不同的组合但又必须要补齐

所以有三种选择 

状况 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 $广告插入处理-> 分组数量判断();







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值