我有一个示例代码:
$size_arr = array(35, 36, 37, 38, 39)
这是phpmyadmin
$result = array();
$data = array(); // query get from table
foreach ($data as $row) {
$result [$row->product_id][] = array($row->color => array($row->size));
}
var_dump($result);
如何为结果数组添加更多的值大小
array(
[1] => array(
'Black' => array(35 => 0, 36 => 40, 37 => 5, 38 => 0, 39 => 20),
'White' => array(35 => 0, 36 => 8, 37 => 12, 38 => 20, 39 => 0)
)
)
答案 0 :(得分:0)
非常简单地将颜色和行大小添加为子数组键
$result = array();
$data = array(); // query get from table
foreach ($data as $row) {
$result [$row->product_id][$row->color][$row->size] = $row->quantity;
}
var_dump($result);