D
D
Dmitry2017-10-23 20:52:51
PHP
Dmitry, 2017-10-23 20:52:51

Merging arrays by values?

Hello!
There are two arrays:

array(2) {
  [0]=>
  array(1) {
    [431]=>
    array(1) {
      [0]=>
      string(3) "914"
    }
  }
  [1]=>
  array(1) {
    [432]=>
    array(2) {
      [0]=>
      string(3) "922"
      [1]=>
      string(3) "923"
    }
  }
}

How to get two array like:
array(2) {
  [0]=>914 and 922
  [1]=>914 and 923
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2017-10-23
@Immortal_pony

function joinByValue(array $arrays) {
    $joined = [];
    
    foreach ($arrays as $values) {
        foreach ($values as $i=>$value) {
            $joined[$i][] = $value;
        }
    }
    
    return $joined;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question