2017-08-05 49 views
1
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"} 

從不同的查詢另一個陣列要添加或想要兩個新陣列合併到3個更早陣列

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與空值。

回答

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) 
+0

ANKIT先生,在結果我得到只有一個陣列,而我需要3個陣列 –

+0

請不要叫先生,以及你查詢使用foreach。 –

+0

兄弟,請您詳細說明或告訴我使用編碼 –