这是我的 SQL 表:
order_id | product_id | deal_title | currency_code | total | date_modified
我的问题是如何在 PHP 中创建一个数组,如下所示:
Array
(
[product_id_num1] => Array
(
[order_id]
[deal_title]
[currency_code]
[total]
[date_modified]
)
[product_id_num2] => Array
(
[order_id]
[deal_title]
[currency_code]
[total]
[date_modified]
)
[product_id_num3] => Array
(
[order_id]
[deal_title]
[currency_code]
[total]
[date_modified]
)
etc....
)
谢谢!
最佳答案
你可以尝试下面的方法
$arr = array();
while($row = mysqli_fetch_assoc($query_result)) {
$id = $row['product_id'];
unset($row['product_id']);
$arr[$id] = $row;
}
关于php - SQL 表中的多维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24916842/