title: Recursively create multidimensional array from string explodes
body: <p>I have an array containing a lot category strings like</p>
  
  <pre><code>Cars &gt; Model1
  Cars &gt; Model1 &gt; Accessories
  Cars &gt; Model1 &gt; Something
  Cars &gt; Model2
  Cars &gt; Model3
  </code></pre>
  
  <p>which I want to recursively transform into a multidimensional array where "Cars" is the parent element of Model1, Model2 and Model3.</p>
  
  <p>And of course, "Accessories" and "Something" would be child elements of Model1.</p>
  
  <p>Have been trying to work out the logic behind this for quite some time now, and I just can't seem to figure it out...</p>
  
  <p>Edit: What I have so far, it's not much. As mentioned, can't seem to figure out the logic behind how to develop this.</p>
  
  <pre><code>$array = array(
          'Cars &gt; Model1',
          'Cars &gt; Model1 &gt; Accessories',
          'Cars &gt; Model1 &gt; Something',
          'Cars &gt; Model2',
          'Cars &gt; Model3'
      );
  
      for ($i = 0; $i &lt; count($array); $i++) {
          $name = explode('&gt;', $array[$i]);
  
          // somehow check if the current "name" is already pushed to a new array - if it is, then add as a child.
      }
  </code></pre>