亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

循環遍歷包含另一個數組集合的數組

循環遍歷包含另一個數組集合的數組

PHP
牛魔王的故事 2021-10-22 12:51:46
我試圖獲取日期和課程名稱的值,但我收到了這些錯誤異常。環形:array:2 [▼ 0 => Collection {#284 ▼#items: array:3 [▼  0 => {#277 ▼    +"date": "2018"  }  1 => {#279 ?}  4 => {#282 ?}`` ] } 1 => Collection {#283 ▼  #items: array:2 [▼   0 => {#280 ▼     +"id": 1     +"courseName": "newc1"     }  1 => {#271 ?}  ]  }  ] //tried these  @foreach ($result as $key=> $value)                    @foreach ($value as $val)                        {{$val->date}}                    @endforeach                @endforeach       //controller        $data = array();        $date = db::table('students')->select('date')->get()->unique();        $course = db::table('courses')->select('id', 'courseName')->get();        array_push($data, $date, $course);需要遍歷這些。而是得到了 ErrorException (E_ERROR) 未定義的屬性:stdClass::$date
查看完整描述

2 回答

?
慕娘9325324

TA貢獻1783條經驗 獲得超4個贊

你必須控制數據庫結果,如果它在日期選擇上也可以為 laravel 使用 distinct() 和 get 必須在它之前的最后


    //This

    $date = db::table('students')->select('date')->get()->unique();

    //To This

    $date = db::table('students')->select('date')->distinct()->get();


    if(!$date)

      return $this->response;

      //or

      return false;

//更新


$course = DB::table('students')

            ->select('id','courseName', 'courses')

            ->groupBy('courses')//What ever you want to uniqe

            ->get();

對于返回視圖示例,您必須自己更改


return $this->responseWithView("index //PAGE","success", ['courses' => $course,'anything' => $youwant]);


查看完整回答
反對 回復 2021-10-22
  • 2 回答
  • 0 關注
  • 169 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號