gpt4 book ai didi

PHP - 如何连接两个数组

转载 作者:可可西里 更新时间:2023-11-01 00:56:35 24 4
gpt4 key购买 nike

我有两个数组

  1. print_r($val);

  2. print_r($results);

我需要通过个人 ID 连接这两个数组,例如 array1。 123456 到数组 2。 123456,也是array1 654321到array2 654321

数组 1:

Array (
[1] => Array
(
[0] => test1
[1] => 123456
)

[2] => Array
(
[0] => test2
[1] => 654321
)
)

数组 2:

Array (
[5] => Array
(
[login] => 123456
[firstname] => George
[lastname] => George
)

[8] => Array
(
[personal_id] => 654321
[firstname] => John
[lastname] => John
)

如何连接这两个数组?

谢谢

最佳答案

试试这个。

$new_Array = array();
foreach ($val as $key => $v) {
foreach ($results as $r) {
if($v[1] == $r['login']){
$new_Array[$key]['login'] = $r['login'];
$new_Array[$key]['firstname'] = $r['firstname'];
$new_Array[$key]['lastname'] = $r['lastname'];
$new_Array[$key]['test'] = $v[0];
}
}
}
print_r($new_Array);

关于PHP - 如何连接两个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40861488/

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