gpt4 book ai didi

php - 如何在 PHP 中连接数组值?

转载 作者:可可西里 更新时间:2023-11-01 12:48:18 25 4
gpt4 key购买 nike

我有数组 1:

Array
(
[0] => Array
(
[recomendation_id] => 3588
[employee_id] => 90141063
[attendance_type_id] => 2
[start_dtm] => 2016-05-17 10:32:00
[end_dtm] =>
[request_message] => test notif
[recomendation_status_id] => 1
[last_update_dtm] => 2016-05-17 10:32:43
[employee_name] => Nike Yulistia Angreni
[attd_type_name] => Permittance
[status_name] => Request
)

)

数组2:

Array
(
[0] => Array
(
[valuator1] => Wulan Lastia Permana
)
)

我想在一个数组中创建数组值。我想要这样的结果:

Array
(
[0] => Array
(
[recomendation_id] => 3588
[employee_id] => 90141063
[attendance_type_id] => 2
[start_dtm] => 2016-05-17 10:32:00
[end_dtm] =>
[request_message] => test notif
[recomendation_status_id] => 1
[last_update_dtm] => 2016-05-17 10:32:43
[employee_name] => Nike Yulistia Angreni
[attd_type_name] => Permittance
[status_name] => Request
[valuator1] => Wulan Lastia Permana
)
)

这样可以加入吗?

最佳答案

你必须使用 array_replace_recursive :

<?php

$arr1 = Array
(
Array
(
"recomendation_id" => 3588,
"employee_id" => 90141063,
"attendance_type_id" => 2,
"start_dtm" => "2016-05-17 10:32:00",
"end_dtm" => "",
"request_message" => "test notif",
"recomendation_status_id" => 1,
"last_update_dtm" => "2016-05-17 10:32:43",
"employee_name" => "Nike Yulistia Angreni",
"attd_type_name" => "Permittance",
"status_name" => "Request"
)

);
$arr2 = Array
(
Array
(
"valuator1" => "Wulan Lastia Permana"
)
);

print_r(array_replace_recursive($arr1,$arr2));

结果:

Array
(
[0] => Array
(
[recomendation_id] => 3588
[employee_id] => 90141063
[attendance_type_id] => 2
[start_dtm] => 2016-05-17 10:32:00
[end_dtm] =>
[request_message] => test notif
[recomendation_status_id] => 1
[last_update_dtm] => 2016-05-17 10:32:43
[employee_name] => Nike Yulistia Angreni
[attd_type_name] => Permittance
[status_name] => Request
[valuator1] => Wulan Lastia Permana
)

)

你的 Eval


如果您使用 array_merge_recursive , 你的 output将是:

Array
(
[0] => Array
(
[recomendation_id] => 3588
[employee_id] => 90141063
[attendance_type_id] => 2
[start_dtm] => 2016-05-17 10:32:00
[end_dtm] =>
[request_message] => test notif
[recomendation_status_id] => 1
[last_update_dtm] => 2016-05-17 10:32:43
[employee_name] => Nike Yulistia Angreni
[attd_type_name] => Permittance
[status_name] => Request
)

[1] => Array
(
[valuator1] => Wulan Lastia Permana
)

)

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

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