任何人都可以帮我改造数组。 它实际上是来自MySQL数据库的查询结果。
现有
(
[ITEM] => Array
(
[0] => PRODUCT A
[1] => PRODUCT B
[2] => PRODUCT C
)
[REFERENCE] => Array
(
[0] => 107AW3
[1] => 204RS67O
[2] => 25GTR56
)
通缉:
(
[0] => Array
(
[ITEM] => Product A
[REFERENCE] => 107AW3
)
[1] => Array
(
[ITEM] => Product B
[REFERENCE] => 204RS67O
)
[2] => Array
(
[ITEM] => Product C
[REFERENCE] => 25GTR56
)
如何将阵列转换为想要的阵列? 一瞥信息,它实际上是来自MySQL的查询:
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$item_array[] = $row["item"];
$reference_array[] = $row["reference"];
}
}
table_content = array('ITEM'=>$item_array,
'REFERENCE'=>$reference_array);
echo '<pre>'; print_r($table_content); echo '</pre>';
答案 0 :(得分:2)
您只能使用一个数组:
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$item_array[] = [
'ITEM' => $row["item"],
'REFERENCE' => $row["reference"],
];
}
}