我有一个产品表:
products
-id
-name
-image
还有一个 product_atts 表:
product_attributes
-product_id (FK)
-size (1, 2)
-memebership (1, 2, 3, 4, 6, 11)
-price
现在,当查询product_attributes
表并加入products
表时,我得到了所有的变化:
Array
(
[0] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 1
[membership] => 1
[price] => 0.00
)
[1] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 1
[membership] => 2
[price] => 0.00
)
[2] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 1
[membership] => 3
[price] => 0.00
)
[3] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 1
[membership] => 4
[price] => 0.00
)
[4] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 1
[membership] => 6
[price] => 0.00
)
[5] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 1
[membership] => 11
[price] => 0.00
)
[6] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 2
[membership] => 1
[price] => 0.00
)
[7] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 2
[membership] => 2
[price] => 0.00
)
[8] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 2
[membership] => 3
[price] => 0.00
)
[9] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 2
[membership] => 4
[price] => 0.00
)
[10] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 2
[membership] => 6
[price] => 0.00
)
[11] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => 2
[membership] => 11
[price] => 0.00
)
)
有没有办法让我得到如下所示的结果:
Array
(
[0] => stdClass Object
(
[name] => Product 1
[image] => Product1.png
[size] => stdClass Object
(
[0] => 1,
[1] => 2
)
[membership] => stdClass Object
(
[0] => 1,
[1] => 2,
[2] => 3,
[3] => 4,
[4] => 6,
[5] => 11
)
[price] => 0.00
)
)
它使在我的 UI 等中使用这些数据变得更加容易。