4
4
4uva4ok19052018-05-16 21:55:12
PHP
4uva4ok1905, 2018-05-16 21:55:12

Is it possible to concatenate arrays?

Is it possible to combine the contents of the arrays, if the key is already in use - then nothing, and if not - then you need to add from other arrays, but with an empty value

array(3) {
  [0]=>
        array(4) {
          ["attributes_3_ru-ru"] => "10"
          ["attributes_3_en-gb"] => "100"
          ["attributes_4_en-gb"] => "2222"
          ["attributes_4_ru-ru"] => ""
        }
  [1]=>
        array(2) {
          ["attributes_6_ru-ru"] => "10"
          ["attributes_6_en-gb"] => "100"
        }
    }
  [2]=>
        array(2) {
          ["attributes_4_ru-ru"] => "10"
          ["attributes_4_en-gb"] => "100"
        }
        ...n
}

What would be the output something like this
array(3) {
  [0]=>
        array(4) {
          ["attributes_3_ru-ru"] => "10"
          ["attributes_3_en-gb"] => "100"
          ["attributes_4_en-gb"] => "2222"
          ["attributes_4_ru-ru"] => ""
          ["attributes_6_ru-ru"] => ""
          ["attributes_6_en-gb"] => ""
        }
  [1]=>
        array(2) {
          ["attributes_6_ru-ru"] => "10"
          ["attributes_6_en-gb"] => "100"
          ["attributes_3_ru-ru"] => ""
          ["attributes_3_en-gb"] => ""
          ["attributes_4_en-gb"] => ""
          ["attributes_4_ru-ru"] => ""
        }
    }
  [2]=>
        array(2) {
          ["attributes_4_ru-ru"] => "10"
          ["attributes_4_en-gb"] => "100"
          ["attributes_6_ru-ru"] => ""
          ["attributes_6_en-gb"] => ""
          ["attributes_3_ru-ru"] => ""
          ["attributes_3_en-gb"] => ""
        }
        ...n
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2018-05-16
Alexsev @MaxGoody

Addition of arrays.
$array_one + $array_two...

V
Vasya, 2018-05-17
@haramba

$arr_finished = $arr1 + $arr2 + $arr3 + ...
$arr_finished = array_walk($arr_finished, function(&$v, $k) {
    $v = isset($arr1[$k]) ? $arr1[$k] : "";
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question