php左连接,如何在php中对左联接查询返回的数组数据进...
我有以下具有以下值的2表:
tbl_brand
ID名稱
1個蘋果
2三星
tbl_products
ID brand_id p_name
1個1移動
2個1 Earpods
3 2移動
在這里,當我使用左聯接查詢即
選擇’b’.’id’作為’brand_id’,’b’.’name’作為’brand_name’,’p’.’p_name’作為’product_name’FROM’tbl_brand”b’左聯接’tbl_products”p ‘ON’p’.’brand_id’=’b’.’id’
并打印結果,得到以下數組:
Array
(
[0] => stdClass Object
(
[brand_id] => 1
[brand_name] => Apple
[product_name] => Mobile
)
[1] => stdClass Object
(
[brand_id] => 1
[brand_name] => Apple
[product_name] => Earpods
)
[2] => stdClass Object
(
[brand_id] => 2
[brand_name] => Samsung
[product_name] => Mobile
)
一切正常.但是我正在尋找的結果是這樣的:
Array
(
[0] => stdClass Object
(
[brand_id] => 1
[brand_name] => Apple
[product_name] => stdClass Object
(
[0] => Mobile
[1] => Earpods
)
)
[1] => stdClass Object
(
[brand_id] => 2
[brand_name] => Samsung
[product_name] => Mobile
)
我想根據brand_id鍵對數據進行分組.我怎樣才能做到這一點 ?
總結
以上是生活随笔為你收集整理的php左连接,如何在php中对左联接查询返回的数组数据进...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 疫情重创旅游业 度假胜地印尼巴厘岛10个
- 下一篇: 魅族年终福利来了!魅族17、18/18s