标签:
$arr1 = array("loginname" => "username","psw" => "password");
$arr2 = array("loginname" => "Mike","psw" => 123,"user" => "user123");
//将数组$arr2的‘loginname’‘psw’按照$arr1规定将其替换为新的键名。代码如下:
foreach($arr1 as $key => $value)
{
foreach ($arr2 as $k2=>$v2)
{
if ($key == $k2)
{
unset($arr2[$key]);
$arr2[$value]=$v2;
}
}
}
//打印结果
var_dump($arr2);
var_dump($arr1);
//结果
array (size=3)
‘user‘ => string ‘user123‘ (length=7)
‘username‘ => string ‘Mike‘ (length=4)
‘password‘ => int 123
array (size=2)
‘loginname‘ => string ‘username‘ (length=8)
‘psw‘ => string ‘password‘ (length=8)
标签:
原文地址:http://www.cnblogs.com/dlbird/p/4298224.html