<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Working Beta &#187; tree</title>
	<atom:link href="http://seeds.workingbeta.com/tag/tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://seeds.workingbeta.com</link>
	<description>a bounch of nearly working code</description>
	<lastBuildDate>Wed, 10 Feb 2010 21:25:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>class.tree.php</title>
		<link>http://seeds.workingbeta.com/2008/11/24/classtreephp/</link>
		<comments>http://seeds.workingbeta.com/2008/11/24/classtreephp/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 12:07:41 +0000</pubDate>
		<dc:creator>gc</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Seeds]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[tree]]></category>

		<guid isPermaLink="false">http://seeds.workingbeta.com/?p=33</guid>
		<description><![CDATA[Trees are all around us&#8230; inside and outside our computers. As you may have already seen on your daily basis work, when you deal with tree-like structures binded to tables into your DB, you set something like

id  &#124;  id_father  &#124;      name     &#124; other [...]]]></description>
			<content:encoded><![CDATA[<p>Trees are all around us&#8230; inside and outside our computers. As you may have already seen on your daily basis work, when you deal with tree-like structures binded to tables into your DB, you set something like</p>
<blockquote><p><code><br />
id  |  id_father  |      name     | other datas<br />
01  |                00  |      root           | ...<br />
02  |                01  |  sub node | ...<br />
</code></p></blockquote>
<p>this kind of data structure is usually managed via recursion, and in web applications is useful to store site menu, product categories,  file-system alike apps and so on.<br />
The class i&#8217;m seeding here does all the dirty job giving you the possibility to</p>
<ul>
<li>use custom callback to modify the default behaviour [&lt;ul&gt;&lt;li&gt; sequence]</li>
<li>minimize/maximize function [for folder-like interfaces]</li>
<li>navigation path serialization</li>
</ul>
<p>those are the methods usually needed for day-to-day work with trees.<br />
<a href="http://workingbeta.com/seeds/class.tree.zip">here</a> you find all the code, but I&#8217;d like to poin out two things that [IMHO] really teach something to the average PHP programmer</p>
<ul>
<li>in the <strong>constructor</strong> 3 arrays are build as properties starting from the original array: arrayById, arrayByFather, arrayHasChild. I don&#8217;t know if it would be faster using array_find.. but once we&#8217;ve made the proper index association, ther&#8217;s no need for the original array to be parsed again.</li>
<li>use of $$ for the callback function: not so many people knows this sintax, but it&#8217;s worth a try</li>
</ul>
<p>the rest is really simple, and it&#8217;s well commented as well.</p>
<p>of course it fits perfectly with the standard output from dbmanager class presented <a href="http://seeds.workingbeta.com/2008/11/18/classdbmanagerphp/">here</a>. Set up your table in an appropriate way, make your assocQuery call and use your tree in no time.</p>
]]></content:encoded>
			<wfw:commentRss>http://seeds.workingbeta.com/2008/11/24/classtreephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
