Solved

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

Posted on 2003-10-24
10
199 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
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 …

747 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

11 Experts available now in Live!

Get 1:1 Help Now