Solved

Function to make a visual tree like on windows explorer from an array using PHP

Posted on 2003-10-22
3
274 Views
Last Modified: 2006-11-17
Hi

I have a multi-dimensional array of names which I want to display on screen as a windows-explorer style tree.  I set out to make it myself but am having trouble getting there as it is slightly more involved than I expeted !

Is there a script anyone knows of which can do this for me ?

Thanks
Richard
0
Comment
Question by:rfila
3 Comments
 
LVL 11

Expert Comment

by:shmert
ID: 9600085
So, this is something that you would click branches to toggle visible/hidden, yes?  Or is it just a static display of the tree?
0
 
LVL 6

Accepted Solution

by:
aolXFT earned 250 total points
ID: 9600945
<?php

$array = make_array_of_type_described_in_question();

// Method 1:
var_dump($array);

//Method 2:
print_r($array);

//print_r, and var_dump are similar. They format the output differently.

//Method 3

// A custom recusive function to do the job:
// I can't think of how explorer does it at the minute,
// but you should be able to adapt the following.
function show_array($array, $indent = 0, $indent_diff = 2){
        if(is_array($array)){
                foreach($array as $element){
                        show_array($element, $indent + $indent_diff, $indent_diff);
                }
        }else{
                for($i = 0; $i < $indent; ++$i){
                        echo ' ';
                }
                echo $array . "\n";
        }
}

$indent_diff is just a value by how much difference there is between various levels of indenting.
0
 

Expert Comment

by:kplonk
ID: 9664190
I did it using PHP and Javascript, the PHP handels requesting data ofm rthe DB and builds the javascript, the javascript then expands and colapses the tree as needed.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now