Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Web Development 6 67
What Programs Are Available to Help Map Forms for PDF Creation 11 55
How do i use the await event in php echo 5 41
Code not executing correctly. 3 43
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

737 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