|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+declare(strict_types=1);
|
|
|
|
|
|
namespace app\common\lib;
|
|
|
|
|
@@ -10,7 +11,7 @@ class Arr
|
|
|
* @param $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function getTree($data): array
|
|
|
+ public static function getTree(array $data): array
|
|
|
{
|
|
|
$items = [];
|
|
|
foreach ($data as $v) {
|
|
@@ -26,4 +27,28 @@ class Arr
|
|
|
}
|
|
|
return $tree;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对前端的分类数目进行截取
|
|
|
+ * @param array $data
|
|
|
+ * @param int $firstCount
|
|
|
+ * @param int $secondCount
|
|
|
+ * @param int $threeCount
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function sliceTreeArr(array $data, int $firstCount = 5, int $secondCount = 3, int $threeCount = 5): array
|
|
|
+ {
|
|
|
+ $data = array_slice($data, 0, $firstCount);
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ if (!empty($v['list'])) {
|
|
|
+ $data[$k]['list'] = array_slice($v['list'], 0, $secondCount);
|
|
|
+ foreach ($v['list'] as $kk => $vv) {
|
|
|
+ if (!empty($vv['list'])) {
|
|
|
+ $data[$k]['list'][$kk]['list'] = array_slice($vv['list'], 0, $threeCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
}
|