title: Converting multi-dimensional array to a single HTML-like array?
body: <p>What is the fastest or most convenient possible way to convert a multi-dimensional array to a single HTML-like array (the method that is used to set the <code>name</code> attribute in HTML forms)? For example, </p>
  
  <pre><code>$ar = [
      'x' =&gt; ['a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3],
      'y' =&gt; ['yy' =&gt; ['yyy' =&gt; 3]],
      'z' =&gt; 3333,
      'm' =&gt; [1, 2],
  ];
  </code></pre>
  
  <p>should be converted to:</p>
  
  <pre><code>  $ar = [
          'x[a]' =&gt; 1,
          'x[b]' =&gt; 2,
          'x[c]' =&gt; 3,
          'y[yy][yyy]' =&gt; 3,
          'z' =&gt; 3333,
          'm[0]' =&gt; 1,
          'm[1]' =&gt; 2,
      ];
  </code></pre>
  
  <p>Here is my first try:</p>
  
  <pre><code>$ar = [
      'x' =&gt; ['a' =&gt; 1, 'b' =&gt; 2, 'c' =&gt; 3],
      'y' =&gt; ['yy' =&gt; ['yyy' =&gt; '3']],
      'z' =&gt; 3333,
      'm' =&gt; [1, 'x']
  ];
  
  function convert($key, $value, &amp;$new)
  {
      foreach ($value as $k =&gt; $v) {
          if (is_array($v)) {
              convert($key."[$k]", $v, $new);
          }
          else {
              $new[$key."[$k]"] = $v;
          }
      }
  }
  $r = [];
  convert(null, $ar, $r);
  print_r($r);;
  </code></pre>