PHP-用另一个数组替换数组的值 [英] PHP - replace values of array with another array

查看:484
本文介绍了PHP-用另一个数组替换数组的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将一个数组的值替换为另一个具有相同键的数组的值?

Is there a way i can replace the values of one array with the values of another which has identical keys?

$arr1 = Array
        (
            [key1] => var1
            [key2] => var2
        )
$arr2 = Array
        (
            [key1] => var3
            [key2] => var4
        )

我想将$ arr1的值更改为$ arr2中的值,即时执行此操作约10次,我可以逐行执行,但是我想知道是否有更简单的方法. 谢谢!

I want to change $arr1's values to the ones in $arr2 im doing this about 10 times, and i can do it line by line, but im wondering if there's a simpler way. Thanks!

推荐答案

检查php的 array_merge() 函数.

Check php's array_merge() function.

$arr1 = array_merge($arr1,$arr2);

这篇关于PHP-用另一个数组替换数组的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆