我有一个在php(codeigniter)开发的网站,我想合并一些具有相同结构的数组。 这是我的数组的构造:合并复杂的数组php
$first = array();
$first['hotel'] = array();
$first['room'] = array();
$first['amenities'] = array();
/*
Insert data into $first array
*/
$second = array();
$second['hotel'] = array();
$second['room'] = array();
$second['amenities'] = array();
/*
Insert data into $second array
*/
后插入数据我想合并这个数组,但问题是,我在它里面子阵,我想创造一个独特的阵列那样:
$total = array();
$total['hotel'] = array();
$total['room'] = array();
$total['amenities'] = array();
这是尝试合并:
$total = array_merge((array)$first, (array)$second);
在这阵我只有$第二阵列为什么呢?
我对你想要的输出感到困惑 –
想要的输出是像第一个r秒一样的数组,但是两个数组合并了@SamuelCook –
你可以在找[array_merge_recursive()'](http:// php.net/manual/en/function.array-merge-recursive.php)? – complex857