<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Converting a flat array with Parent ID&#8217;s to a nested Tree</title>
	<atom:link href="http://blog.tekerson.com/2009/03/03/converting-a-flat-array-with-parent-ids-to-a-nested-tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tekerson.com/2009/03/03/converting-a-flat-array-with-parent-ids-to-a-nested-tree/</link>
	<description>The inane, sometimes insane, ramblings from the mind of Brenton Alker.</description>
	<lastBuildDate>Sat, 21 Aug 2010 17:30:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: misz</title>
		<link>http://blog.tekerson.com/2009/03/03/converting-a-flat-array-with-parent-ids-to-a-nested-tree/comment-page-1/#comment-3675</link>
		<dc:creator>misz</dc:creator>
		<pubDate>Tue, 15 Sep 2009 10:32:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tekerson.com/?p=61#comment-3675</guid>
		<description>Hey, function works like a charm, but only if you have only 1 master item. If for example 2 items have parent = null, it returns only last branch of tree. I&#039;ve achieved good results with: 
    //second pass
    $root = null;
    foreach ($indexed as $id =&gt; $row) {
        $indexed[$row[$parentIdField]][$childNodesField][$id] =&amp; $indexed[$id];
        if ($row[$parentIdField] === null) {
            $root = $id;
            $roots[] = $id;
        }
    }
    
    //Had to be modified, beacuse it returned only the last indexed root id
    foreach ($roots as $k) {
    	$return[$k] = $indexed[$k]; 
    }
    return $return;</description>
		<content:encoded><![CDATA[<p>Hey, function works like a charm, but only if you have only 1 master item. If for example 2 items have parent = null, it returns only last branch of tree. I&#8217;ve achieved good results with:<br />
    //second pass<br />
    $root = null;<br />
    foreach ($indexed as $id =&gt; $row) {<br />
        $indexed[$row[$parentIdField]][$childNodesField][$id] =&amp; $indexed[$id];<br />
        if ($row[$parentIdField] === null) {<br />
            $root = $id;<br />
            $roots[] = $id;<br />
        }<br />
    }</p>
<p>    //Had to be modified, beacuse it returned only the last indexed root id<br />
    foreach ($roots as $k) {<br />
    	$return[$k] = $indexed[$k];<br />
    }<br />
    return $return;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brenton Alker</title>
		<link>http://blog.tekerson.com/2009/03/03/converting-a-flat-array-with-parent-ids-to-a-nested-tree/comment-page-1/#comment-1765</link>
		<dc:creator>Brenton Alker</dc:creator>
		<pubDate>Thu, 07 May 2009 06:51:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tekerson.com/?p=61#comment-1765</guid>
		<description>Good point, I can&#039;t see any reason to look for NULL specifically. I&#039;ve gone with a check for boolean false equivalents instead (mainly because empty was causing odd rendering issues and I&#039;m too lazy to figure out why).

Updated again.</description>
		<content:encoded><![CDATA[<p>Good point, I can&#8217;t see any reason to look for NULL specifically. I&#8217;ve gone with a check for boolean false equivalents instead (mainly because empty was causing odd rendering issues and I&#8217;m too lazy to figure out why).</p>
<p>Updated again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sasa Tomislav Mataic</title>
		<link>http://blog.tekerson.com/2009/03/03/converting-a-flat-array-with-parent-ids-to-a-nested-tree/comment-page-1/#comment-1735</link>
		<dc:creator>Sasa Tomislav Mataic</dc:creator>
		<pubDate>Wed, 06 May 2009 10:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tekerson.com/?p=61#comment-1735</guid>
		<description>Hey, sweet function :)

I had one small problem though, my root node had &#039;parentId&#039; = &#039;0&#039;, so when checking if ($row[$parentIdField] === null) it never finds the root node.

better solution may be like this
if (empty($row[$parentIdField]))

I know that === null is faster, but this way was more convenient for me.

Thanks a lot ;)</description>
		<content:encoded><![CDATA[<p>Hey, sweet function <img src='http://blog.tekerson.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I had one small problem though, my root node had &#8216;parentId&#8217; = &#8216;0&#8242;, so when checking if ($row[$parentIdField] === null) it never finds the root node.</p>
<p>better solution may be like this<br />
if (empty($row[$parentIdField]))</p>
<p>I know that === null is faster, but this way was more convenient for me.</p>
<p>Thanks a lot <img src='http://blog.tekerson.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brenton Alker</title>
		<link>http://blog.tekerson.com/2009/03/03/converting-a-flat-array-with-parent-ids-to-a-nested-tree/comment-page-1/#comment-1562</link>
		<dc:creator>Brenton Alker</dc:creator>
		<pubDate>Thu, 30 Apr 2009 12:47:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tekerson.com/?p=61#comment-1562</guid>
		<description>Right you are. That&#039;s what I get for &quot;fixing&quot; code without testing it.

Updated post.</description>
		<content:encoded><![CDATA[<p>Right you are. That&#8217;s what I get for &#8220;fixing&#8221; code without testing it.</p>
<p>Updated post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel Jirák</title>
		<link>http://blog.tekerson.com/2009/03/03/converting-a-flat-array-with-parent-ids-to-a-nested-tree/comment-page-1/#comment-1560</link>
		<dc:creator>Pavel Jirák</dc:creator>
		<pubDate>Thu, 30 Apr 2009 12:16:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tekerson.com/?p=61#comment-1560</guid>
		<description>hi,

may there is mistake, because item id = 4 has parentId = 1 not 3. Second problem is in return value of function. Index 0 isn&#039;t in array.</description>
		<content:encoded><![CDATA[<p>hi,</p>
<p>may there is mistake, because item id = 4 has parentId = 1 not 3. Second problem is in return value of function. Index 0 isn&#8217;t in array.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
