Solved

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

Posted on 2003-10-24
10
201 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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