Skip to content

Instantly share code, notes, and snippets.

View ravyg's full-sized avatar

Ravish Gupta ravyg

View GitHub Profile
@ravyg
ravyg / simple_to_nestedarray.php
Created March 19, 2012 08:06
takes in simple array to generate hierarchical nested array #tree #graph
<?php
function hierarchical_array_from_array($farray){
foreach ($flatArray as $key=>$flat) {
$nodes = array();
$tree = array();
foreach ($flatArray as $key=>&$node) {
$node["Children"] = array();
$id = $node["@id"];
$parent_id = $node["@parentId"];
$nodes[$id] =& $node;