Re: PEAR::Tree walk function usage

From: Date: Thu, 13 Feb 2003 12:56:48 +0000
Subject: Re: PEAR::Tree walk function usage
References: 1 2 3 4 5  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3735@lists.php.net to get a copy of this message
if 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']);
i forgot the first parameter, the 'id' here i think $tree->update($node['id'],'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.
Hi Wolfram,
Well it almost worked instantly, very cool. I only had to make somes minor changes (I would have very been impressed if you had written flawless code just in your email client ;-) Anyway the biggest problem is that I don't want to save the data to the DB. It's just for display purposes. Can I do that? I just want to change the array, not save any changes to the datasource. Or is that something I should just take care of myself, something that should not be the responsibility of the PEAR::Tree class? Cheers Jeroen

« previous php.pear.general (#3735) next »