0

Currently if I do this:

$array1 = [27476, 29173, 24551, 21109, 29754, 19116, 25924, 27406, 26878, 20866, 32889, 25975];

$array2 = [25959, 26427, 26775, 24968, 24501, 27218, 27441, 27353, 25074, 27344, 26794, 25355];

$data = array_merge(
    array_merge_recursive(
        $array1, 
        $array2
    )
);

I get this:

    array3 = [
    0: 25959
    1: 26427
    2: 26775
    3: 24968
    4: 24501
    5: 27218
    6: 27441
    7: 27353
    8: 25074
    9: 27344
    10: 26794
    11: 25355
    12: 27476
    13: 29173
    14: 24551
    15: 21109
    16: 29754
    17: 19116
    18: 25924
    19: 27406
    20: 26878
    21: 20866
    22: 32889
    23: 25975 
    ];

Is it possible to merge it like the following?:

    array3 = [
    0 => [27476, 25959]
    1 => [29173, 26427]
    2 => [24551, 26775]
    .
    .
    .
    .
    ];

I wanted without iteration, its possible maybe using php7+ which I am not familiar.

Any help would be appricated.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Malarivtan
  • 404
  • 1
  • 6
  • 20
  • https://stackoverflow.com/a/47421337/2943403 – mickmackusa Jan 21 '19 at 15:15
  • More important questions for me are: 1. Where are these input arrays coming from? Database? File? 2. Where is this data going that you need them to be repackaged? Json? Database query? – mickmackusa Jan 22 '19 at 04:26

1 Answers1

7

I don't understand what is the problem with iteration, but still:

$result = array_map(null, $array1, $array2);

Based on array_map behaviour with null as first argument.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • I guess like this: https://stackoverflow.com/questions/54098206/merge-values-from-different-arrays-to-one-with-the-same-key/54098417#54098417 – dWinder Jan 21 '19 at 14:48