Explode the results to add a nested tree to a database in PHP and order it
<p>I'm using a nestedsortable jQuery plugin that gives me the order/sort of the elements serialized.</p>

<p>And example of this serialitzation (root means parent_id=0):</p>

<pre><code>id[1]=root&amp;id[5]=1&amp;id[2]=1&amp;id[3]=1&amp;id[4]=3
</code></pre>

<p>First thing I'll do is explode by &amp;:</p>

<pre><code>$serialized = "id[1]=root&amp;id[5]=1&amp;id[2]=1&amp;id[3]=1&amp;id[4]=3";

$exploded = explode("&amp;", $serialized);
</code></pre>

<p>But I don't know then how to manage a <code>id[1]=root</code> or <code>id[3]=1</code>. How I can do it?</p>

<p>And another question. In this way I don't know which is how to store the order. When I've the exploded with in array like <code>array("id"=&gt;1, "parent"=&gt;"root");</code> I've to store the order. I will do it with an index, but how I recognise nested levels?</p>

<p>An example:</p>

<pre><code>$i = 0;

foreach($exploded as $explode)
{
    //update every id in MySQL and set parent=$explode["parent"] and order=$i
    $i++;
}
</code></pre>

<p>But if I've N levels, how I can have a index $i for every one of them?</p>

<p>Thank you in advance!</p>
