Reputation: 2748
I have two array()
My first array :
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
)
)
and this
Array
(
[session_id] => 16:09:15:59
)
So my question is how to insert my second array to my first array. So the result become like this :
[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
)
I have try array_merge
but the result doesn't like what i desire. When i use array_merge
i get this result
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
)
here is my PHP
foreach ($xml->HeaderTemp as $HeaderTempnya)
{
$HeaderTemp[] = $HeaderTempnya;
}
Upvotes: 3
Views: 38
Reputation: 1202
@bfahmi it almost working
Try to change it like this
foreach($first_array as $key => $value){
$first_array[$key]->session_id = $second_array['session_id'];
}
Upvotes: 2
Reputation: 798
foreach($first_array as $key => $value){
$first_array[$key]['session_id'] = $second_array['session_id'];
}
Upvotes: 1