The "easiest" way to do that kind of output is "recursion"
It's a kind of iteration/looping thing where a function calls itself.
Sample:
function fact($x){
if ($x == 0){
return 1;
}
else{
return $x * fact($x - 1);
}
}
Basically the function eats itself rather like those Russion porcelain dolls
nestled inside each other.
It's easier to "reverse" your data structure to get it to work though:
$tingtang[0] = array(1, 7);
$tingtang[1] = array(2, 4);
$tingtang[2] = array(3);
.
.
.
IE, each tingtang knows its "children", rather than the parent.
In your case it would be something like:
function tingtang($tt, $depth = 0){
global $tingtang;
echo str_repeat("nbsp;", $depth * 4), "tingtang$ttBR\n";
while (list(,$child) = each($tingtang[$tt])){
tingtang($child, $depth+1);
}
}
tingtang(0);
Note: Recursion has an overhead at each function call -- So very "deep"
trees can become performance problems.
For a much more in-depth look at this sort of thing, check out the rather
long threads about "forums" and "recursion" in the PHP Mailing List
archives. (Probably back in version 3 archives, actually)
--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
- Original Message -
From: Christian Sakshaug [EMAIL PROTECTED]
Newsgroups: php.general
Sent: Thursday, January 25, 2001 12:34 PM
Subject: [PHP] Anyone who can help me making a loop of this?
Anyone who can help me making a loop of this?
http://www.sakshaug.net/phps/loop.txt
I have tried many things, but I can't get it perfect...
Best Regards, Christian Sakshaug
--
Email: [EMAIL PROTECTED]
Web: www.sakshaug.net
Tel: +47 913 95 618
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]