Solved

sorting out arrays that came from string.......

Posted on 2003-10-24
10
200 Views
Last Modified: 2008-03-06
function getDirList($base)
{
    if(is_dir($base)){
        $dh = opendir($base);
        $i = 0;
        while (false !== ($dir = readdir($dh))) {
            if (is_dir($base . $dir) && $dir !== '.' && $dir !== '..'  && $dir!== '_vti_cnf') {
                $subs = $dir    ;
                $subbase = $base . $dir . '/';
//or $start = 0;
                $exp = array();
                $exp = explode(' ',$subs);
//or for ($i = 0; $i<count ($subs); $i++){
//$output[$i] = $temp_output = substr($subs, $start);
//$start++
                asort($exp);
                reset($exp);
                foreach($exp as $key => $val){
//or while (list($key,$val) = each($exp)) {
                $val1 = $val;
                $val = explode(":",$val);
                if (preg_match("/GALLERY_/", $val1)){
                 print'<a href=' . $subbase . '>' . $exp[0] . "<br></a>";}
                else {
                print '</div></span><br><SPAN class="main" onMouseOver="abc(this)" onMouseOut="def(this)">'
. $exp[0] . '<div class="sub" style="display: none;"><br>';}
                }
                getDirList($subbase);
                } else {next;}
            }
         
       
        }
        closedir($dh);
0
Comment
Question by:ramonklown
  • 6
  • 4
10 Comments
 
LVL 2

Author Comment

by:ramonklown
ID: 9613964
That code up there makes a list of arrays from directory names and it works just fine, now i want to know how to order the arrays by alfabetical order... and how can i order out the subdirectories within them to match... well the first part is the most important I can break my head on the second part
0
 
LVL 14

Accepted Solution

by:
ThG earned 125 total points
ID: 9614076

i don't understand this:
                $exp = explode(' ',$subs);

what's the purpopse of this? it's clueless..

anyway to order your directories first fetch all files inside it and then call sort() on the resulting array.

something like (concept code)
 while (false !== ($dir = readdir($dh)))
    $dir_list[] = $dir;
  sort($dir_list);
  foreach ($dir_list as $dir) {
     ...rest of the code should be identical.
  }
0
 
LVL 2

Author Comment

by:ramonklown
ID: 9614304
the explode is to make the directory names into arrays...

the dir is not an array, it is a a string with all the directory names....

So the function is tranforming the string into arrays and now i want to organize the arrays but it seems like there is a block to only being able to organize the first array but thanks for the comment it's making me think a little differently about the code...:)
0
 
LVL 14

Expert Comment

by:ThG
ID: 9614371

note that the explode() call is wrong, because readdir() returns one directory per call..that's why it's inside a while() loop!
your code works only because you probably don't have directory names containing spaces, otherwise it would fail..
0
 
LVL 2

Author Comment

by:ramonklown
ID: 9614432
that is the point :) no directory name with spaces other wise it would blow up the hole system....and yes it is wrong but till now I haven't found any functions that do tha conversion automatically..... it would be nice dough....

so i'm beginning to think that is impossible unless I get out of this while crap.... I'm testing some new stuff let's wait and see how far php can go...... :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:ramonklown
ID: 9626526
what I did was:

first:
Figured out that it was exploding and creating a different array.. so i used array_merge do get them all into one array $exp1 and used asort and reset to organize it out nicely and now I have a nice old sorted array....
0
 
LVL 14

Expert Comment

by:ThG
ID: 9626937
"old sorted"? what do you mean?

you are talking about "converting", converting what? still refering to your original code, you can remove the explode(), the reset() and the asort() because they are all useless, and the foreach loop as well, and moving the code inside it in the upper level.
0
 
LVL 2

Author Comment

by:ramonklown
ID: 9644737
Sorry to waste your time man... I already solved the problem.... The thing is that this code up there was doomed to death so I got this code from Devshed and changed it a bit and did just what I wanted.....

I needed asort to sort out the arrays to list the folder in alfabetical order.

foreach....I can say that I love PHP because of this little word.... specially when talking about arrays...

So what do I do now? do I give points to myself? haha :) that is why I don't like this points **** is like a competition for points... not a knowledge trade
0
 
LVL 14

Expert Comment

by:ThG
ID: 9645338

Well I think I helped you (or tried to), so you could assign them to my first reply.. or ask to PAQ/Delete this question.
If you don't like "this points s***" then you probably shouldn't use this forum.
0
 
LVL 2

Author Comment

by:ramonklown
ID: 9649574
You you did try to help me out and your first answer had the array that I used so I guess you get the points.....

And yeah you are right about not using this forum.... Dev Shed is better....no competition for points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

943 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

10 Experts available now in Live!

Get 1:1 Help Now