help with some nasty recursive algorithm

From: Date: Fri, 16 Mar 2001 00:11:45 +0000
Subject: help with some nasty recursive algorithm
Groups: php.general 
Request: Send a blank email to php-general+get-67473@lists.php.net to get a copy of this message
I need some help with an algorithm that I'm writing to build a categories array, based on the mysql table. the table goes by: id_category, name_category, parent_category and with a simple query, with a group by and after doing a little for(;;) processing, I get the following array.. categ | parent | num_childs null 1 1 null 4 0 1 5 2 5 6 0 5 7 0 well... I have a function called CatName($id) that returns me the name of that giving its ID... so, I want from that array build a new array like this: [0]["id"] = 1 [0]["name"] = Electronics [1]["id"] = 5 [1]["name"] = Electronics/Palm [2]["id"] = 6 [2]["name"] = Electronis/Palm/WindowsCE [3]["id"] = 7 [3]["name"] = Electronis/Palm/PalmOS [3]["id"] = 4 [3]["name"] = Food preety nasty hun? I know its something recursive... but I can't figure out how to "walk" trough the array to get this kind of output... any help will be welcome.. thanks...

« previous php.general (#67473) next »