gpt4 book ai didi

php - 添加数组两个其他数组PHP

转载 作者:可可西里 更新时间:2023-11-01 01:16:10 26 4
gpt4 key购买 nike

我有两个 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
)
)

还有这个

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;
}

最佳答案

@bfahmi 它几乎工作

试试这样改

foreach($first_array as $key => $value){
$first_array[$key]->session_id = $second_array['session_id'];
}

关于php - 添加数组两个其他数组PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com