我得到以下代码来从数据库中获取数据以存储在PHP的数组中:
<?php
$keyemail = "testmail@testmailer.com";
$sql = mysqli_query($con, "SELECT * FROM crypto_data WHERE email = '$keyemail'");
while($row = mysqli_fetch_array($sql)){
$myCoins[] = array($row['currency'], $row['amount'], $row['price_when_bought']);
}
var_dump($myCoins);
?>
我得到的数组看起来像这样:
array(2) {
[0] => array(3) {
[0] => string(3) "BTC"[1] => string(1) "2"[2] => string(2) "23"
}
[1] => array(3) {
[0] => string(3) "IOT"[1] => string(1) "6"[2] => string(2) "74"
}
}
如何更改我的代码以获取如下所列的阵列?这样$ row ['currency']是每个数组的数组标题。
array(2) {
["BTC"] => array(2) {
["balance"] => int(2) ["boughtprice"] => int(23)
}
["ETH"] => array(2) {
["balance"] => int(6) ["boughtprice"] => int(74)
}
}
一只萌萌小番薯