gpt4 book ai didi

php数组将一个数组的值添加到另一个数组

转载 作者:行者123 更新时间:2023-11-29 03:52:04 25 4
gpt4 key购买 nike

我有 2 个数组,它们都是从单独的 mysql 查询生成的,如下所示:

数组 1

[0] => Array
(
[value] => black
[hex_colour] => #000000
)

[1] => Array
(
[value] => blue
[hex_colour] => #4e5f98
)

[2] => Array
(
[value] => brown
[hex_colour] => #a3775e
)

阵列 2

[0] => Array
(
[value] => black
[count] => 122
)

[1] => Array
(
[value] => blue
[count] => 33
)

[2] => Array
(
[value] => brown
[count] => 5
)

我的问题是如何将 [count] 添加到 ARRAY 1,以便结果为:

新建数组

[0] => Array
(
[value] => black
[hex_colour] => #000000
[count] => 122
)

[1] => Array
(
[value] => blue
[hex_colour] => #4e5f98
[count] => 33
)

[2] => Array
(
[value] => brown
[hex_colour] => #a3775e
[count] => 5

)

抱歉,我没有尝试过的代码示例,但我使用许多不同的搜索词搜索了谷歌,但没有成功。将不胜感激任何帮助。

最佳答案

$data= Array(
'value' => 'black',
'hex_colour' => '#000000'
);
$data1= Array(
'value' => 'black',
'count' => '122'
);


print_r(array_merge($data1, $data));

关于php数组将一个数组的值添加到另一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47978382/

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