在php中,我有两个数组:
$a = ['name'=>'a','age'=>'b','city'=>'c'];
$b = ['name'=>'z','age'=>'x','city'=>'y'];
now i want a new array like:
name=a,
age=b,
city=c,
add=arry(name=a,age=b,city=c)
如何获得这种格式的数组
答案 0 :(得分:1)
您可以使用array_merge()
函数来创建新数组。演示:https://3v4l.org/jKGNB
$a = ['name'=>'a','age'=>'b','city'=>'c'];
$new_array = array_merge($a, ['add' => $a]);
OR,
将新数组复制为输入数组,然后将新键推入其中。演示:https://3v4l.org/birP6
$a = ['name'=>'a','age'=>'b','city'=>'c'];
$new_array = $a;
$new_array['add'] = $a;