返回域php的名称服务器数组
我想用php返回一个域的名称服务器,但是我只在数组中放入一个名称服务器 这是我正在使用的代码:返回域php的名称服务器数组,php,arrays,laravel,dns,Php,Arrays,Laravel,Dns,我想用php返回一个域的名称服务器,但是我只在数组中放入一个名称服务器 这是我正在使用的代码: //get auth ns datat $authnsData = dns_get_record($domain, DNS_NS); //put the results into a nice array foreach ($authnsData as $nsinfo) { $authns = array( 'nsdata' => array(
//get auth ns datat
$authnsData = dns_get_record($domain, DNS_NS);
//put the results into a nice array
foreach ($authnsData as $nsinfo)
{
$authns = array(
'nsdata' => array(
'nameserver' => $nsinfo['target'],
'ip' => $this->getnsIP($nsinfo['target']),
'location' => $this->getipLocation($this->getnsIP($nsinfo['target'])),
),
);
return $authns;
}
我得到的结果是:
Array
(
[nsdata] => Array
(
[nameserver] => ns-us.1and1-dns.org
[ip] => 217.160.83.2
[location] =>
)
)
假设一个域有两个或多个名称服务器,我只将其中一个添加到数组中
如果要测试它以找出问题,代码位于以下文件中:
函数是getAuthNS和LookupAuthNS。在任何人建议使用for循环之前,我已经尝试了for($num=0;)类型的循环
$authns
分配一个新数组,而不是将其推入请尝试以下代码:
foreach ($authnsData as $nsinfo)
{
$authns[] = [
'nsdata' => [
'nameserver' => $nsinfo['target'],
'ip' => $this->getnsIP($nsinfo['target']),
'location' => $this->getipLocation($this->getnsIP($nsinfo['target'])),
],
];
}
return $authns;
顺便说一句,不需要运行两次
getnsIP
。您可以改为使用此选项:
foreach ($authnsData as $nsinfo)
{
$nameserver = $nsinfo['target'];
$ip = $this->getnsIP($nameserver);
$location = $this->getipLocation($ip);
$authns[] = ['nsdata' => compact('nameserver', 'ip', 'location')];
}
return $authns;