php数组包数据递归

//获取分类
public static function getCategoryMultipleChoose($shopId)
{
    $categories = Category::where('shop_id', $shopId)
        ->where('status', '启用')
        ->select(['category_id','category_name', 'parent_id'])
        ->get()->toArray();
    return self::format($categories);
}

private static function format($categories, $parentId = 0)
{
    $newData = [];
    foreach ($categories as $k => $category) {
        $data['title'] = $category['category_name'];
        $data['key'] = $category['category_id'];
        $data['value'] = $category['category_id'];
        if ($category['parent_id'] == $parentId){
            $data['children'] = self::format($categories, $category['category_id']);
            $newData[] = $data;
        }

    }
    return $newData;
}

nba2k2球员数据

nba2k2球员数据
请先登录后发表评论
  • 最新评论
  • 总共0条评论