1

我有一些代码假设要打印域的名称服务器。然而,在打印它们时,它给了我这个:

array(5) {
  [0]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(19) "remote1.easydns.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(32)
  }
  [1]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(19) "remote3.easydns.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(32)
  }
  [2]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(15) "ns2.easydns.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(32)
  }
  [3]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(15) "ns1.easydns.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(32)
  }
  [4]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(19) "remote2.easydns.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(32)
  }
}

我知道这是一个数组但是我只希望它打印每个名称服务器

remote2.easydns.com
ns1.easydns.com
ns2.easydns.com
remote1.easydns.com

等等

这是我当前的代码:

<?php
$result = dns_get_record("php.net", DNS_NS);
echo '<pre>';
var_dump($result);
echo '</pre>';
?>

Print_r 做了一个非常相似的事情。

4

2 回答 2

3

假设您的数组具有变量名称$array

foreach($array as $key=>$value){
    echo $value['target'].'<br>';
}
于 2012-12-02T21:19:48.380 回答
2

$result是一个结果数组。遍历数组并输出target每个子数组的键。

$result = dns_get_record("php.net", DNS_NS);
foreach ($result as $record) {
    echo $record['target'], "\n";
}
于 2012-12-02T21:20:06.060 回答