I need to merge two arrays wich have the following format:
array(9)
{
[0]=> array(1) { ["BLA"]=> string(7) "bis 050" }
[1]=> array(1) { ["BLA"]=> string(7) "bis 060" }
[2]=> array(1) { ["BLA"]=> string(7) "bis 070" }
[3]=> array(1) { ["BLA"]=> string(7) "bis 080" }
[4]=> array(1) { ["BLA"]=> string(7) "bis 090" }
[5]=> array(1) { ["BLA"]=> string(7) "bis 100" }
[6]=> array(1) { ["BLA"]=> string(7) "bis 110" }
[7]=> array(1) { ["BLA"]=> string(7) "bis 120" }
[8]=> array(1) { ["BLA"]=> string(6) "gr 120" }
}
array(5)
{
[0]=> array(2) {
["BLA"]=> string(7) "bis 050"
["Amount"]=> string(3) "832" }
[1]=> array(2) {
["BLA"]=> string(7) "bis 060"
["Amount"]=> string(3) "448" }
[2]=> array(2) {
["BLA"]=> string(7) "bis 090"
["Amount"]=> string(4) "1216" }
[3]=> array(2) {
["BLA"]=> string(7) "bis 100"
["Amount"]=> string(4) "1024" }
[4]=> array(2) {
["BLA"]=> string(7) "bis 110"
["Amount"]=> string(3) "896" }
}
I tried array_merge()
and array_merge_recursive()
but it does not work.
My goal is to write the second key and its value from array2 (Amount) into array 1 where the value for the first key (BLA) is identical. In addition I would like to write "Amount":"0"
, if there is no corresponding value in array2. Is there any way to do this with php?
The result should look like the following:
Result:
{
[0]=> array(2) {
["BLA"]=> string(7) "bis 050"
["Amount"]=> string(3) "832" }
[1]=> array(2) {
["BLA"]=> string(7) "bis 060"
["Amount"]=> string(3) "448" }
[2]=> array(2) {
["BLA"]=> string(7) "bis 070"
["Amount"]=> string(1) "0" }
[3]=> array(2) {
["BLA"]=> string(7) "bis 080"
["Amount"]=> string(1) "0" }
[4]=> array(2) {
["BLA"]=> string(7) "bis 090"
["Amount"]=> string(4) "1216" }
[5]=> array(2) {
["BLA"]=> string(7) "bis 100"
["Amount"]=> string(4) "1024" }
[6]=> array(2) {
["BLA"]=> string(7) "bis 110"
["Amount"]=> string(3) "896" }
[7]=> array(2) {
["BLA"]=> string(7) "bis 120"
["Amount"]=> string(1) "0" }
[8]=> array(2) {
["BLA"]=> string(6) "gr 120"
["Amount"]=> string(1) "0" }
}