我有兩個array()
我的第一個數組:陣列添加其他兩個數組PHP
Array
(
[0] => SimpleXMLElement Object
(
[ID] => 14212
[TransactionNo] => 20160712-K-DTS2-14273
[TransactionDate] => 2016-07-12T10:55:09.023+07:00
[TotalTransaction] => 14000
[LocationID] => 1
[UserID] => 1224
[CustomerCode] => K-DTS2
[SendStatus] => true
)
[1] => SimpleXMLElement Object
(
[ID] => 14213
[TransactionNo] => 20160712-K-DTS2-14274
[TransactionDate] => 2016-07-12T11:24:31.84+07:00
[TotalTransaction] => 12900
[LocationID] => 1
[UserID] => 1224
[CustomerCode] => K-DTS2
[SendStatus] => true
)
)
這
Array
(
[session_id] => 16:09:15:59
)
所以我的問題是如何將我的第二陣列插入到我的第一個數組。所以,結果變成了這個樣子:
[0] => SimpleXMLElement Object
(
[ID] => 14212
[TransactionNo] => 20160712-K-DTS2-14273
[TransactionDate] => 2016-07-12T10:55:09.023+07:00
[TotalTransaction] => 14000
[LocationID] => 1
[UserID] => 1224
[CustomerCode] => K-DTS2
[SendStatus] => true
[session_id] => 16:09:15:59
)
我有嘗試array_merge
但結果不喜歡我的願望。當我使用array_merge
我得到這個結果
Array
(
[0] => SimpleXMLElement Object
(
[ID] => 2144
[TransactionNo] => 20160713-K-LFJBLP-02158
[TransactionDate] => 2016-07-13T11:32:33.6+07:00
[TotalTransaction] => 74900
[LocationID] => 1
[UserID] => 11418
[CustomerCode] => K-LFJBLP
[SendStatus] => true
)
[session_id] => 16:09:19:52
)
這裏是我的PHP
foreach ($xml->HeaderTemp as $HeaderTempnya)
{
$HeaderTemp[] = $HeaderTempnya;
}
添加到兩個對象? – splash58
'foreach($ array2 as $ key => $ value) $ array1 [0] - > addChild($ key,$ value);' – splash58