I have some multi dimensional array that needs to be merged while preserving some of it's values.
Array
(
[diagnosa_id] => 6
[jeniskelamin] => LAKI-LAKI
[diagnosa] => Array
(
[0] => Array
(
[diagnosa_kode] => A01.0
[jeniskelamin] => LAKI-LAKI
[pasienhidupmati] => HIDUP
[diagnosa_nama] => Demam tifoid
[jmlpasien] => 1
)
[4] => Array
(
[diagnosa_kode] => A01.0
[jeniskelamin] => LAKI-LAKI
[pasienhidupmati] => HIDUP
[diagnosa_nama] => Demam tifoid
[jmlpasien] => 1
)
)
)
Array
(
[diagnosa_id] => 1
[jeniskelamin] => LAKI-LAKI
[diagnosa] => Array
(
[1] => Array
(
[diagnosa_kode] => A00
[jeniskelamin] => LAKI-LAKI
[pasienhidupmati] => HIDUP
[diagnosa_nama] => Kolera
[jmlpasien] => 1
)
[2] => Array
(
[diagnosa_kode] => A00
[jeniskelamin] => LAKI-LAKI
[pasienhidupmati] => HIDUP
[diagnosa_nama] => Kolera
[jmlpasien] => 1
)
)
)
Array
(
[diagnosa_id] => 7
[jeniskelamin] => LAKI-LAKI
[diagnosa] => Array
(
[3] => Array
(
[diagnosa_kode] => A01.1
[jeniskelamin] => LAKI-LAKI
[pasienhidupmati] => HIDUP
[diagnosa_nama] => Demam paratifoid A
[jmlpasien] => 1
)
)
)
As you can see, the first two array have a similar data on [diagnosa] array. I need to combine the array inside the [diagnosa] array.
So if the array inside it have same value on it's [diagnosa_kode], [jeniskelamin], [pasienhidupmati], and [diagnosa_nama], then it should add the [jmlpasien] value, while preserving the other value.
For example, on the first array, the result should be like this:
Array
(
[diagnosa_id] => 6
[jeniskelamin] => LAKI-LAKI
[diagnosa] => Array
(
[0] => Array
(
[diagnosa_kode] => A01.0
[jeniskelamin] => LAKI-LAKI
[pasienhidupmati] => HIDUP
[diagnosa_nama] => Demam tifoid
[jmlpasien] => 2
)
)
)
Sorry if it's too complicated, but I just can't figure it out on implementing it on php.