A list is used to process tree data (the adjacent list). an existing array $ d & nbsp ;=& nbsp; array (& nbsp; 'ads ', & nbsp; 1, & nbsp; 0 & nbsp;), & nbsp; array)
An existing array
$ D = array (
Array ('bulletins ', 1, 0 ),
Array ('Article ', 2, 0 ),
Array ('Article 1', 3, 2 ),
Array ('Article 2', 4, 2 ),
Array ('Article 1 comment', 5, 3 ),
Array ('Article 2 comment', 6, 4 ),
Array ('Article 1 comment 1', 7, 3 ),
Array ('Article 1 Comments ', 8, 5 ),
);
Expected output:
Announcement
Article
Article 1
Article 1 comment
Article 1 comment
Article 1 comment 1
Article 2
Article 2 comment
So you can
foreach($d as $t) list($a[$pid][$id], $id, $pid) = $t;
Get
Array
(
[0] => Array
(
[1] => Announcement
[2] => article
)
[2] => Array
(
[3] => Article 1
[4] => Article 2
)
[3] => Array
(
[5] => Article 1 comments
[7] => Article 1 comment 1
)
[4] => Array
(
[6] => Article 2 comment
)
[5] => Array
(
[8] => Article 1 comments
)
)
We can see that the data is clustered by 3rd columns.
So we can use a recursive function to display data.
function foo($ar, $pid=0, $deep=0) {
foreach($ar[$pid] as $k=>$v) {
printf("%s%s\n", str_repeat(' ', $deep), $v);
if(isset($ar[$k])) foo($ar, $k, $deep+2);
}
}
Call foo ($ );
Share The php list tree:
------ Solution --------------------
Moderator is a good guy
------ Solution --------------------
Bamboo has a special liking for an infinite number of trees.
Every time you read it, there are new gains.
------ Solution --------------------
------ Solution --------------------
Study in the front row!
------ Solution --------------------
I learned. Haha
------ Solution --------------------
------ Solution --------------------
It turns out to be like this.
------ Solution --------------------
It's really concise, learning.
------ Solution --------------------
Well written. I learned.
------ Solution --------------------
Static void Main (string [] args)
{
Double a, B, c, p, h, area;
Console. Write ("Enter the triangle side :");
String s = Console. ReadLine ();
A = double. Parse (s );
Console. Write ("Enter the triangle side B :");
S = Console. ReadLine ();
B = double. Parse (s );
Console. Write ("Enter the triangle side C :");
S = Console. ReadLine ();
C = double. Parse (s );
If (a> 0 & B> 0 & c> 0 & a + B> c & a + c> B & B + c>)