I have never written recursion before (actually, thinking about it, I have no idea about algorithms at all). I happened to have this need, so I tried to write it and found that it is quite easy. I will record it in particular.
The database is dedecms default, dede_arctype is the table that saves the column, and reid is the parent column id of the column.
<span><span>$array</span> = <span>array</span><span>(); get_sons(</span><span>$type</span>, <span>$array</span><span>); </span><span>var_dump</span>(<span>$array</span><span>); </span><span>function</span> get_sons(<span>$type</span>, &<span>$current_array</span><span>){ </span><span>$result</span> = <span>mysql_query</span>("select id from dede_arctype where reid = {<span>$type</span>}"<span>); </span><span>while</span>(<span>$row</span> = <span>mysql_fetch_assoc</span>(<span>$result</span><span>)){ </span><span>$current_array</span>[] = <span>$row</span>['id'<span>]; get_sons(</span><span>$row</span>['id'], <span>$current_array</span><span>); } }</span></span>