-4

My array is like this:

Array (
  [0] => Array (
    [0] => aaa-aaa
    [SKU] => aaa-aaa
    [1] => 12/1/1
    [date] => 12/1/1
    [2] => 1.15
    [cost] => 1.15 )
  [1] => Array (
    [0] => bbb-bbb
    [SKU] => bbb-bbb
    [1] => 10/1/1
    [date] => 10/1/1
    [2] => 0.15
    [cost] => 0.15 )
)

I'd like to merge the matching values to each other, or make a new array selecting the indexes, or use a php tool to print specified indexes to csv: aaa-aaa, 12/1/1, 1.15 \n bbb-bbb, 10/1/1, 0.15

It cannot be queried because this information is coming from 4 different tables, from 2 different sql providers. These arrays are the result of mapping previous arrays.

array_unique() doesn't work, array_diff() doesn't work, array_diff_key() doesn't work.

You direction is much appreciated!

K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
mezzomix
  • 305
  • 2
  • 12

1 Answers1

0

This will do it:

$result = array_unique($input);
print_r($result);

If you want keep only string keys:

 $result = array();
foreach ($array as $key => $value){
  if(!is_numeric($key)
     $result[$key]=$value;
  }

In your case the array size should always be even and has no gaps between indexes so you can do something like:

$length = count($array)/2;
for ($i = 0; $i < $length; $i++) {
  unset($array[i]);
}

You can also do:

 $dummy = array_fill(0, count($input), 'banana');
 $result = array_diff_key($input, $dummy);
USER249
  • 1,080
  • 7
  • 14
  • 2
    You'll lose all of the string keys and if you have any other duplicate data other than the matching pair you will lose that as well. – AbraCadaver Feb 12 '18 at 19:51
  • Thank you for your answers but they did not work for me. array_reduce() worked. – mezzomix Feb 12 '18 at 20:52