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

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

Laravel - 將集合轉換為簡單數組

Laravel - 將集合轉換為簡單數組

PHP
子衿沉夜 2023-04-02 14:58:40
所以我有這段代碼:    $collectionOfProducts = \DB::table('products_specif')->whereIn('size',$arrayOfAttributes)->whereIn('color',$arrayOfAttributes)->whereIn('material',$arrayOfAttributes)->get('product_code');    $product_codes = $collectionOfProducts->unique();    dd($product_codes->toArray());    $arrayOfProducts = \DB::table('products')->whereIn('product_code',$product_codes)->get();    return view('pages.products', compact('arrayOfProducts','type'));dd() 響應:array:4 [▼  0 => {#1252 ▼    +"product_code": "SocksCode"  }  4 => {#1257 ?}  9 => {#1262 ?}  13 => {#1266 ?}]我想在我的whereIn語句中使用 $product_codes,但我不能因為開頭的那些數字 (0,4,9,13)。如何將此集合/數組轉換為簡單的“product_code”:“code”數組?
查看完整描述

1 回答

?
開心每一天1111

TA貢獻1836條經驗 獲得超13個贊

您可以使用 pluck 方法獲取數組product_code


$product_codes= \DB::table('products_specif')

->whereIn('size',$arrayOfAttributes)

->whereIn('color',$arrayOfAttributes)

->whereIn('material',$arrayOfAttributes)->pluck('product_code')->toArray();


$arrayOfProducts = \DB::table('products')->whereIn('product_code',$product_codes)->get();



查看完整回答
反對 回復 2023-04-02
  • 1 回答
  • 0 關注
  • 212 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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