Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - merge/combine array values in multidimensional array
    primarykey
    data
    text
    <p>How could I convert this array:</p> <pre><code>$a = array( 0 =&gt; array( 0 =&gt; 31, 1 =&gt; 39 ), 1 =&gt; array( 0 =&gt; 41 ) ); </code></pre> <p>to this one:</p> <pre><code> $a = array( 0 =&gt; array( 0 =&gt; array( 0 =&gt; 31, 1 =&gt; 41 ), 1 =&gt; array( 0 =&gt; 39, 1 =&gt; 41 ) ), 1 =&gt; array( 0 =&gt; array( 0 =&gt; 41, 1 =&gt; 31 ), 1 =&gt; array( 0 =&gt; 41, 1 =&gt; 39 ) ) ); </code></pre> <p>I tried several ways, but find no proper solution. At the moment my brain is overheated. So maybe someone has a solution for me.</p> <p>Thanks @Manos.</p> <p>Unfortunatly there are dynamic arrays. So these static function wont work for me.</p> <p>So the array could also look like this:</p> <pre><code>$a = array( 0 =&gt; array( 0 =&gt; 31, 1 =&gt; 39 ), 1 =&gt; array( 0 =&gt; 41, 1 =&gt; 49, 2 =&gt; 51 ), 2 =&gt; array( 0 =&gt; 73 ) ); </code></pre> <p>Output should look like this:</p> <pre><code> $a = array( 0 =&gt; array( 0 =&gt; array( 0 =&gt; 31, 1 =&gt; 41, 2 =&gt; 73 ), 1 =&gt; array( 0 =&gt; 31, 1 =&gt; 49, 2 =&gt; 73 ), 2 =&gt; array( 0 =&gt; 31, 1 =&gt; 51, 2 =&gt; 73 ), 3 =&gt; array( 0 =&gt; 39, 1 =&gt; 41, 2 =&gt; 73 ), 4 =&gt; array( 0 =&gt; 39, 1 =&gt; 49, 2 =&gt; 73 ), 5 =&gt; array( 0 =&gt; 39, 1 =&gt; 51, 2 =&gt; 73 ), 1 =&gt; array( 0 =&gt; array( 0 =&gt; 41, 1 =&gt; 31, 2 =&gt; 73 ), 1 =&gt; array( 0 =&gt; 41, 1 =&gt; 39, 2 =&gt; 73 ), 2 =&gt; array( 0 =&gt; 49, 1 =&gt; 31, 2 =&gt; 73 ), 3 =&gt; array( 0 =&gt; 49, 1 =&gt; 39, 2 =&gt; 73 ), etc ...... ) ); </code></pre> <p>Manos function Output:</p> <pre><code> array(3) { [0]=&gt; array(8) { [0]=&gt; array(2) { [0]=&gt; int(31) [1]=&gt; int(41) } [1]=&gt; array(2) { [0]=&gt; int(39) [1]=&gt; int(41) } [2]=&gt; array(2) { [0]=&gt; int(31) [1]=&gt; int(49) } [3]=&gt; array(2) { [0]=&gt; int(39) [1]=&gt; int(49) } [4]=&gt; array(2) { [0]=&gt; int(31) [1]=&gt; int(51) } [5]=&gt; array(2) { [0]=&gt; int(39) [1]=&gt; int(51) } [6]=&gt; array(2) { [0]=&gt; int(31) [1]=&gt; int(73) } [7]=&gt; array(2) { [0]=&gt; int(39) [1]=&gt; int(73) } } [1]=&gt; array(9) { [0]=&gt; array(2) { [0]=&gt; int(41) [1]=&gt; int(31) } [1]=&gt; array(2) { [0]=&gt; int(49) [1]=&gt; int(31) } [2]=&gt; array(2) { [0]=&gt; int(51) [1]=&gt; int(31) } [3]=&gt; array(2) { [0]=&gt; int(41) [1]=&gt; int(39) } [4]=&gt; array(2) { [0]=&gt; int(49) [1]=&gt; int(39) } [5]=&gt; array(2) { [0]=&gt; int(51) [1]=&gt; int(39) } [6]=&gt; array(2) { [0]=&gt; int(41) [1]=&gt; int(73) } [7]=&gt; array(2) { [0]=&gt; int(49) [1]=&gt; int(73) } [8]=&gt; array(2) { [0]=&gt; int(51) [1]=&gt; int(73) } } [2]=&gt; array(5) { [0]=&gt; array(2) { [0]=&gt; int(73) [1]=&gt; int(31) } [1]=&gt; array(2) { [0]=&gt; int(73) [1]=&gt; int(39) } [2]=&gt; array(2) { [0]=&gt; int(73) [1]=&gt; int(41) } [3]=&gt; array(2) { [0]=&gt; int(73) [1]=&gt; int(49) } [4]=&gt; array(2) { [0]=&gt; int(73) [1]=&gt; int(51) } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload