title: Sorting out array of parent child relations where two children share a parent from an array and display it using div
body: <p>I have the following data which gets served from a neo4j query, The data that gets sent back is in the format</p>
  
  <pre><code>home-&gt;parent-&gt;child1
  home-&gt;parent-&gt;child2
  
  home-&gt;parent2-&gt;child1
  
  home-&gt;parent3-&gt;child1
  home-&gt;parent3-&gt;child2
  home-&gt;parent3-&gt;child3
  </code></pre>
  
  <p>I am trying to use javascript to display html which should be like this</p>
  
  <pre><code>&lt;div id="parent1"&gt;
    &lt;div id="child1"&gt;&lt;/div&gt;
    &lt;div id="child2"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="parent2"&gt;
    &lt;div id="child1"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>i tried loopong throigh the query and trying to get the parent to be the index of an object and the child to be values under it</p>
  
  <p>i would do this like this in php</p>
  
  <pre><code>$jsonContents = (object)("parent"=&gt;"child","parent"=&gt;"child"....);
  $array = array();
  foreach($jsonContents as $jsCo=&gt;$jsoCont){
    $array[$jsoCont-&gt;parent][] = $jsoCont-&gt;child;
  }
  </code></pre>
  
  <p>this would return the</p>
  
  <p>$array as</p>
  
  <pre><code>home-&gt;parent1-&gt;[0]-&gt;child
               -&gt;[1]-&gt;child
        parent2-&gt;[0]-&gt;child...
  </code></pre>
  
  <p>This would let me avoid the check for uniqueness of the home parent category as well as put them in a hierarchy so i can interpret it properly in my View part of MVC, to create my div structure.</p>
  
  <p>this is the url for the example json data</p>
  
  <p><a href="http://www.jsoneditoronline.org/?id=bdda268982eb431d361c25e9035bbc99" rel="nofollow">http://www.jsoneditoronline.org/?id=bdda268982eb431d361c25e9035bbc99</a></p>