Re: PEAR::Tree walk function usage
| From: | Wolfram Kriesing | Date: | Wed, 12 Feb 2003 14:29:54 +0000 |
| Subject: | Re: PEAR::Tree walk function usage | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-3707@lists.php.net to get a copy of this message | ||
Jeroen Houben wrote:
Convert: Chapter on Horses -- subchapter -- subchapter ------sub sub chapter ------sub sub chapter Chapter on Camels -- subchapter -- subchapter ------sub sub chapter ------sub sub chapter Into: 1.Chapter on Horses -- 1.1subchapter -- 1.2subchapter ------ 1.2.1sub sub chapter ------ 1.2.2sub sub chapter 2. Chapter on Camels -- 2.1subchapter ------2.1.1.sub sub chapter ------2.1.2sub sub chapter -- 2.2subchapter ------2.2.1sub sub chapter ------2.2.2sub sub chapterif you want to rename all of the chapters persistently (which means to save the changes in the DB too) then you could do the following for the Memory_* way this will work function _walkTree($node) {
global $tree,$levels;
$curLevel = $node['level'];
if (!isset($levels[$curLevel])) {
$levels[$curLevel] = 1;
} else {
$levels[$curLevel]++;
}
$tree->update('name'=>implode('.',$levels).$node['name']);
}
$levels = array();
$tree->walk('_walkTree');
// and rebuild the internal tree structure again, might not
// be necessary since the structure has not changed
$tree->setup();
try this, it could work :-) i just hacked it down here in this mail. i have not tested it!!! if something doesnt work, let me know. but this is the way to go.
--
Wolfram
... opensource @ vision:produktion ...
http://opensource.visionp.de
... translating template engine ....
http://sf.net/projects/simpletpl
... authentication system ....
http://sf.net/projects/auth