App\services\CategoryService::unlimitedForLevel PHP Méthode

unlimitedForLevel() public static méthode

组合一维数组
public static unlimitedForLevel ( array $cate, string $html = '--', integer $pid, integer $level ) : array
$cate array
$html string
$pid integer
$level integer
Résultat array
    public static function unlimitedForLevel($cate, $html = '--', $pid = 0, $level = 0)
    {
        $arr = array();
        foreach ($cate as $k => $v) {
            if ($v['pid'] == $pid) {
                $v['level'] = $level + 1;
                $v['html'] = str_repeat($html, $level);
                $arr[] = $v;
                $arr = array_merge($arr, self::unlimitedForLevel($cate, $html, $v['id'], $level + 1));
            }
        }
        return $arr;
    }

Usage Example

 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $categories = $this->repository->orderBy('id', 'desc')->paginate(15);
     $selectedCategory = CategoryService::unlimitedForLevel($categories->toArray()['data']);
     $category = $this->repository->find($id);
     return view('backend.news.category_edit', ['category' => $category, 'selectCategory' => $selectedCategory]);
 }
All Usage Examples Of App\services\CategoryService::unlimitedForLevel