There is a multidimensional array:

Array ( [0] => Array ( [came ati 3000] => 417 ) [1] => Array ( [came ati 3000 купить] => 0 ) [2] => Array ( [came ati 3000 цена] => 0 ) [3] => Array ( [came ati 3000 цена] => 84 ) ) 

It is necessary to convert to such one-dimensional:

 Array ( [came ati 3000] => 417 [came ati 3000 купить] => 0 [came ati 3000 цена] => 0 [came ati 3000 цена] => 84 ) 

I tried this:

 $arrOut = array(); foreach($arrIn as $subArr){ $arrOut = array_merge($arrOut,$subArr); } 

or

 $arrOut = call_user_func_array('array_merge', $arrIn); 

... but with such options all merge into one with the same values, thus:

 Array ( [came ati 3000] => 417 [came ati 3000 купить] => 0 [came ati 3000 цена] => 84 ) 

, and I need to get all the elements in a new one-dimensional array!

  • 3
    the array can not have two identical keys - splash58
  • I understood @ splash58 ... ... then tell me how to be in my situation, I initially needed to compare numerical values ​​in strings and if the text matches, then leave that digital value greater than zero ... I put the lines in the array for that breaking the key into pairs => value to compare the value and remove unnecessary - cheh1
  • And if the key is only with a zero value, is it still to delete? and what to do if several nonzero values? - splash58
  • @ splash58 if only with zero, then leave .. if there is a double with a large zero, then we leave it. The meaning is as follows: I get phrases, check whether each phrase contains the word "buy" or "price" if not, then create a double with a zero value ... so I go over everything .. and then I have to do what I described in the first sentence of this comment. - cheh1

1 answer 1

 $arrOut = array(); foreach($arrIn as $subArr){ // разберем подмассив на ключи и значения foreach($subArr as $key => $val){ // если значение с таким ключом существует, и оно больше текущего, то ничего не делаем if(isset($arrOut[$key]) && $arrOut[$key] > $val) continue; // добавляем значение во внешний массив $arrOut[$key] = $val; } }