我有这样的数组我想要主机阵列和IP阵列,我想将特定的IP地址添加到唯一的主机名作为密钥。
[chns_host] => Array
(
[0] => ns1.dafhsdfhfhdkfd.com
[1] => ns2.dafhsdfhfhdkfd.com
[2] => ns1.dafhsdfhfhdkfd.com
[3] => ns2.dafhsdfhfhdkfd.com
)
[chns_ip] => Array
(
[0] => 149.56.51.28
[1] => 149.56.51.29
[2] => 149.56.51.30
[3] => 149.56.51.31
)
我想将此数组转换为
[ns1.dafhsdfhfhdkfd.com] => Array
(
[0] => 149.56.51.28
[1] => 149.56.51.30
)
[ns2.dafhsdfhfhdkfd.com] => Array
(
[0] => 149.56.51.29
[1] => 149.56.51.31
)
Ip需要使用特定的密钥主机名。
答案 0 :(得分:1)
您可以通过以下方式订购:(仅当主机中的行数等于ips中的行数时才有效)
$array = <yourArray>;
$newArray = array();
foreach($array['chns_host'] as $id => value){
$newArray[$value][] = $array['cnhs_ip'][$id];
}
var_dump($newArray);