Solved

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

Posted on 2003-10-24
10
202 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
[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
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

730 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