Solved

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

Posted on 2003-10-22
3
271 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php mail headers 2 12
Mail Not Sent 6 42
Wordpress type image upload 10 30
php connect() failed error 25 16
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

21 Experts available now in Live!

Get 1:1 Help Now