Hi i have problem with merge array,
How to merge array from different array
From Here
Array 1
array:6 [
"patient_name" => "Pasien 4"
"employee_no" => "1114"
"birth_date" => "1990-05-02"
"gender" => "L"
"department_code" => "D0004"
"section_code" => "S0004"
]
Array 2
array:2 [
"kd_layan" => "10000104 "
"nama_layan" => "PAKET MCU ADVANCE (MALE)"
]
To Here
array:8 [
"patient_name" => "Pasien 4"
"employee_no" => "1114"
"birth_date" => "1990-05-02"
"gender" => "L"
"department_code" => "D0004"
"section_code" => "S0004"
"kd_layan" => "10000104 "
"nama_layan" => "PAKET MCU ADVANCE (MALE)"
]
Any solution for this problem?
Thanks
It has very simple solution using array_merge()
function of php.
array_merge()
function merges one or more arrays into one array.
You can assign one array to the function, or as many as you like. If two or more array elements have the same key, the last one overrides the others.
in your case use it as below
$arr1=[
"patient_name" => "Pasien 4",
"employee_no" => "1114",
"birth_date" => "1990-05-02",
"gender" => "L",
"department_code" => "D0004",
"section_code" => "S0004"
];
$arr2=[
"kd_layan" => "10000104 ",
"nama_layan" => "PAKET MCU ADVANCE (MALE)"
];
print_r(array_merge($arr1,$arr2));
for more see documentation