Line | |
---|
1 | <?php |
---|
2 | // Page heirarchy experiment. |
---|
3 | // Looking for the ideal array. |
---|
4 | $heir = array( |
---|
5 | 'id' => '1', |
---|
6 | 'title' => 'Home', |
---|
7 | 'url' => '/index.php', |
---|
8 | array( |
---|
9 | 'id' => '2', |
---|
10 | 'title' => 'Products', |
---|
11 | 'url' => '/products/', |
---|
12 | array( |
---|
13 | 'id' => '4', |
---|
14 | 'title' => 'Plastic Bags', |
---|
15 | 'url' => '/products/plastic_bags.php' |
---|
16 | ), |
---|
17 | array( |
---|
18 | 'id' => '5', |
---|
19 | 'title' => 'Paper Bags', |
---|
20 | 'url' => '/products/paper_bags.php' |
---|
21 | ), |
---|
22 | array( |
---|
23 | 'id' => '6', |
---|
24 | 'title' => 'Vomit Bags', |
---|
25 | 'url' => '/products/vomit_bags.php' |
---|
26 | ) |
---|
27 | ), |
---|
28 | array( |
---|
29 | 'id' => '3', |
---|
30 | 'title' => 'Services', |
---|
31 | 'url' => '/services/', |
---|
32 | array( |
---|
33 | 'id' => '7', |
---|
34 | 'title' => 'Bag cleaning', |
---|
35 | 'url' => '/services/cleaning.php' |
---|
36 | ), |
---|
37 | array( |
---|
38 | 'id' => '8', |
---|
39 | 'title' => 'Bag disposal', |
---|
40 | 'url' => '/services/disposal.php' |
---|
41 | ) |
---|
42 | ) |
---|
43 | ); |
---|
44 | function printHeir($node, $parent=0, $n=0) |
---|
45 | { |
---|
46 | if (is_array($node) && !empty($node)) { |
---|
47 | echo str_repeat(' ', $n) . $node['title'] . ' => ' . $node['url'] . ' (' . $parent . ',' . $node['id'] . ') ' . '<br />'; |
---|
48 | foreach ($node as $key=>$val) { |
---|
49 | if (is_array($val) && !empty($val)) { |
---|
50 | printHeir($val, $node['id'], $n+1); |
---|
51 | } |
---|
52 | } |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | ?><pre><h1>Formatted array data:</h1><?php |
---|
57 | printHeir($heir); |
---|
58 | ?><br /><br /><h1>Raw array data:</h1><?php |
---|
59 | print_r($heir); |
---|
60 | ?></pre> |
---|
Note: See
TracBrowser
for help on using the repository browser.