} } } print "=== SERIALIZING OBJECTS ===\n"; // Aggregate and save if ($outfile) { $json = new JsonSerializer('cache', 'json', $outfile); $xml = new XmlSerializer('cache', 'xml', $outfile); } else { $json = new JsonSerializer('cache', 'json'); $xml = new XmlSerializer('cache', 'xml'); } foreach ($roots as $id => $root) { if (!$id) { // Minor bug continue; } $node = $nodes->open($id, null); $parts = explode('.', $id); foreach ($ids as $child_id) { $child_parts = explode('.', $child_id); if (count($child_parts) == count($parts) + 1 && strpos($child_id, "{$id}.") === 0 && !array_key_exists($child_id, $roots)) { $node['#children'][array_pop($child_parts)] = $nodes->open($child_id, null); } } print "{$id}\t\t" . memory_get_usage() . "\n"; flush(); $json->setObject($id, $node); $xml->setObject($id, $node); } // * Assemble parent/child relationships