如何在PHP中加入数组值? [英] How to join array values in PHP?
本文介绍了如何在PHP中加入数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有数组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
)
)
我想在一个数组中创建数组值.我想要这样的结果:
I want to make array values in one array. I want result like this:
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
)
)
您的评估
如果您使用 array_merge_recursive ,则您的
If you use array_merge_recursive, your output will be:
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中加入数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文