0

I have source data array like this:

$data = [
  'A' => 'test',
  'B' => [1, 2],
  'C' => [3, 4],
];

There can be different number of keys. In the example we have 3. The value of every key can be array or string.

Now I need to generate from this array the new one (using keys from source array) like this:

$newData = [
    0 => [
        'A' => 'test',
        'B' => 1,
        'C' => 3,
    ],
    1 => [
        'A' => 'test',
        'B' => 1,
        'C' => 4,
    ],
    2 => [
        'A' => 'test',
        'B' => 2,
        'C' => 3,
    ],
    3 => [
        'A' => 'test',
        'B' => 2,
        'C' => 4,
    ],
];

Start implementing the solution but maybe someone have something similar.

  • `Start implementing the solution` - So where is your code? Where are you stuck? What is not working? [ask] – DarkBee Jul 28 '21 at 13:15
  • I do not have anything yet. I just started do this. – Daniel Częstki Jul 28 '21 at 13:16
  • 1
    Something similar: https://stackoverflow.com/questions/8567082/how-to-generate-in-php-all-combinations-of-items-in-multiple-arrays – Daniel Częstki Jul 28 '21 at 13:24
  • So there's no question, you just want to see if someone else will beat you to it? – Lucan Jul 28 '21 at 13:31
  • @Lucan - no. I could not find the similar solution for it. that is why I asked question. But of course I continued searching and start implementing my own solution. But in the end I found the similar solution. – Daniel Częstki Jul 28 '21 at 13:45

0 Answers0