想要添加或想要将两个新数组合并为3个早期数组

时间:2017-08-05 04:58:19

标签: php arrays codeigniter

array_1 = {"challenge_id":"1","user_id":"2","username":"abc","challenge_balance":"1million","bet":"lyf","challenge_name":"disaster","plan":"enjoy","challenge_type":"Me","c_type":"challenge"}

array 2 = {"challenge_id":"8","user_id":"2","username":"abc","challenge_balance":"1million","bet":"lyf","challenge_name":"disaster","plan":"enjoy","challenge_type":"Me","c_type":"challenge"},

array_3 = {"challenge_id":"9","user_id":"2","username":"abc","challenge_balance":"1million","bet":"lyf","challenge_name":"disaster","plan":"enjoy","challenge_type":"Me","c_type":"challenge"}

来自不同查询的另一个数组

array 1= {"project_id":"1","project_name":"2","description":"testing","p_type":"project","project_balance":"1trillion","hatred_ressented":"dontknow"}

array 2 = {"challenge_id":"9","user_id":"2","username":"abc","challenge_balance":"1million","bet":"lyf","challenge_name":"disaster","plan":"enjoy","challenge_type":"Me","c_type":"challenge"}

我希望结果应该在3个数组中 这意味着第一个数组应该与第一个数组合并 第二个数组由两者组合而成 第三个数组为数组1,为null。

1 个答案:

答案 0 :(得分:0)

只需将它们与array_merge()

合并即可
$merge_array = array_merge(first_array, second_array);

示例:

$one =  array('one'=>1, 'two'=>2);

$two =  array('three'=>1, 'four'=>2);

$three =  array('five'=>1, 'six'=>2);

$merge_array = array_merge($one, $two);


$merge_three = array_merge($merge_array, $three);

print_r($merge_three);

//THE result

Array ( [one] => 1 [two] => 2 [three] => 1 [four] => 2 [five] => 1 [six] => 2 )