Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

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

Posted on 2003-10-22
3
Medium Priority
?
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 750 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

647 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