Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this should do it...</p> <pre><code>&lt;?php function convert2dTo3d($source) { $refs = array(); $output = array(); foreach ($source AS $key =&gt; $val) { $tok = strtok($key, '[]'); $prev_tok = NULL; while ($tok !== FALSE) { $this_ref =&amp; $refs[$tok]; if ($prev_tok === NULL) $output[$tok] =&amp; $this_ref; else $refs[$prev_tok][$tok] =&amp; $this_ref; $prev_tok = $tok; $tok = strtok('[]'); if ($tok === FALSE) $refs[$prev_tok] = $val; } } return $output; } // Test $source = array( 'matrix[min_rows]' =&gt; '0', 'matrix[max_rows]' =&gt; '', 'matrix[col_order][]' =&gt; 'col_new_1', 'matrix[cols][col_new_0][type]' =&gt; 'text', 'matrix[cols][col_new_1][type]' =&gt; 'text', 'matrix[cols][col_new_0][label]' =&gt; 'Cell 1', 'matrix[cols][col_new_1][label]' =&gt; 'Cell 2', 'matrix[cols][col_new_0][name]' =&gt; 'cell_1', 'matrix[cols][col_new_1][name]' =&gt; 'cell_2', 'matrix[cols][col_new_0][instructions]' =&gt; '', 'matrix[cols][col_new_1][instructions]' =&gt; '', 'matrix[cols][col_new_0][width]' =&gt; '33%', 'matrix[cols][col_new_1][width]' =&gt; '', 'matrix[cols][col_new_0][settings][maxl]' =&gt; '', 'matrix[cols][col_new_0][settings][fmt]' =&gt; 'none', 'matrix[cols][col_new_0][settings][content]' =&gt; 'all', 'matrix[cols][col_new_1][settings][maxl]' =&gt; '140', 'matrix[cols][col_new_1][settings][multiline]' =&gt; 'y', 'matrix[cols][col_new_1][settings][fmt]' =&gt; 'none', 'matrix[cols][col_new_1][settings][content]' =&gt; 'all', ); echo "&lt;pre&gt;"; print_r(convert2dTo3d($source)); echo "&lt;/pre&gt;"; </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.
    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