0
首先,我不確定標題是否正確,但這是我想要做的。我想使用從DB中選擇的數組,並在for loop
內使用它。當我轉儲數組時(//print_r($ns1);
)它可用。不過print_r($host);
轉儲沒有數據的時候我是print_r
吧。我認爲問題出在$host[] = "@$ns1 $subdomain";
,但我不太確定。爲什麼我不能print_r($host);
?請提前幫助和感謝。將數組與外部數組結合使用
$sql = "SELECT subdomain, ns1, ns2, id_user, counter FROM ns WHERE counter = 1";
$result = mysqli_query($con,$sql);
$subdomain = array();
$ns1 = array();
$ns2 = array();
$id_user = array();
$counter = array();
// Associative array
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){;
$subdomain []= $row['subdomain'];
$ns1 []= $row['ns1'];
$ns2 []= $row['ns2'];
$id_User[]= $row['id_user'];
$counter []= $row['counter'];
}
$total= count($subdomain);
$host = array();
$ip = array();
$mx = array();
for ($x = 1; $x <= $total; $x++) {
//print_r($subdomain); // both data is available
//print_r($ns1);
$host[] = "@$ns1 $subdomain";
print_r($host);
$ip = `/usr/bin/dig $host +short A`;
$mx = `/usr/bin/dig $host +short MX`;
print_r($host);
}