title: JavaScript two-dimensional Array to PHP
body: <p>I have to send a two-dimensional JavaScript Array to a PHP page.
  Indeed, I'm working on a form-builder, in which the user can add or remove fields.<br>
  These fields are added (or removed) using JavaScript (jQuery). When the user is done and hit a 'publish' button, I have to get all the fields concerned and send them to a PHP page which would build a real form with it.<br>
  I found a way to do it but I'm pretty sure it's not very clean :</p>
  
  <pre><code>addedFields = new Array();
  $("#add-info .field").each(function() {
      addedFields.push(new Array($(this).find('.name').val(), $(this).find('.type').val(), $(this).find('.size').val()));
  });
  </code></pre>
  
  <p>Basically, the "<code>.field</code>" class objects are <code>&lt;tr&gt;</code> and the "<code>.name</code>", "<code>.type</code>" and "<code>.size</code>" objects are inputs.<br>
  So I get an array of <code>[name, type, size]</code>, then I convert it into a string using</p>
  
  <pre><code>addedFields = addedFields.join(";");
  </code></pre>
  
  <p>Finally, I go to the PHP form that way ;</p>
  
  <pre><code>document.location.href = "create.php?addedfields=" + addedFields;
  </code></pre>
  
  <p>Concerning the PHP code, I create a PHP array using the <code>explode()</code> function: </p>
  
  <pre><code>$addedFields = explode(";", $_GET['addedfields']);
  </code></pre>
  
  <p>and then I use it again for each element in the array: </p>
  
  <pre><code>foreach ($addedFields as $field) {
      $field = explode(",", $field);
      echo "&lt;li&gt;Field with name : '$field[0]', of '$field[1]' type and with a size of $field[2]&lt;/li&gt;";
  }
  </code></pre>
  
  <p>So it works, but it seems very dirty...</p>