我有这个分贝
id | domain | whois_server |
---------------------------------------
1 | ac | whois.nic.ac |
2 | ae | whois.nic.ae |
3 | id | whois.pandi.or.id |
如何显示不带id的数组形式的数组?
array (
'ac' => 'whois.nic.ac',
'ae' => 'whois.nic.ae',
'id' => 'whois.pandi.or.id',
)
我已经完成以下代码:
$sql = "SELECT * FROM whois_server ";
$result = $db->prepare($sql);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$whoisservers = array_merge($whoisservers, array_map('trim', explode(",", $row[1])));
}
但是出现的是:
array (
[0] => whois.nic.ac
[1] => whois.nic.ae
[2] => whois.pandi.or.id
)
最佳答案
$sql = "SELECT * FROM whois_server ";
$result = $db->prepare($sql);
$result->execute();
$dataReturn = [];
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$dataReturn[$row['domain']] = $row['whois_server'];
}
print_r($dataReturn);
关于php - 显示数据库中的数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55303410/