Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-10-24
10
Medium Priority
?
205 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 250 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
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 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 …
Suggested Courses

610 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