|
|
|
@ -13,6 +13,7 @@
|
|
|
|
|
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
|
|
|
|
|
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
declare (strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace DtApp\ThinkLibrary\helper;
|
|
|
|
|
|
|
|
|
@ -28,7 +29,7 @@ class Arrays
|
|
|
|
|
* @param $arr
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function rand($arr)
|
|
|
|
|
public function rand(array $arr)
|
|
|
|
|
{
|
|
|
|
|
return array_rand($arr);
|
|
|
|
|
}
|
|
|
|
@ -38,9 +39,30 @@ class Arrays
|
|
|
|
|
* @param $arr
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function randValue($arr)
|
|
|
|
|
public function randValue(array $arr)
|
|
|
|
|
{
|
|
|
|
|
return $arr[array_rand($arr)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分隔数组
|
|
|
|
|
* @param array $data 数组
|
|
|
|
|
* @param int $num 数量
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function split(array $data, $num = 5): array
|
|
|
|
|
{
|
|
|
|
|
$arrRet = array();
|
|
|
|
|
if (!isset($data) || empty($data)) return $arrRet;
|
|
|
|
|
$iCount = count($data) / $num;
|
|
|
|
|
if (!is_int($iCount)) $iCount = ceil($iCount);
|
|
|
|
|
else $iCount += 1;
|
|
|
|
|
for ($i = 0; $i < $iCount; ++$i) {
|
|
|
|
|
$arrInfos = array_slice($data, $i * $num, $num);
|
|
|
|
|
if (empty($arrInfos)) continue;
|
|
|
|
|
$arrRet[] = $arrInfos;
|
|
|
|
|
unset($arrInfos);
|
|
|
|
|
}
|
|
|
|
|
return $arrRet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|