SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sorting array... it won't sort

    I am having trouble seeing why this will not sort the list using rsort to get the list sorted in reverse... I also need to find a way to sort it for filemtime() any ideas for that as well (so the last modified file shows on top)?

    Thanks

    PHP Code:
    <?php

    $filelist 
    scandir('c:/test/'); 

    $files = array();

    foreach(
    $filelist as $file){
        
        if(
    strpos($file,'.')!==0){
            
    array_push($files$file);
        }
    }

    $pages array_chunk($files'10');

     
    $page = (int)$_GET['page'];
    $pages[$page];

    for(
    $i 1$i count($pages) +1$i++) { 
    ?>

    <a href="?page=<?php echo $i;?>"><?php echo $i?></a><br />

    <?php 
    }

    rsort($pages);

    foreach(
    $pages[$page-1] as $file) {
        
        echo 
    $file "<BR />";
    }

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    array_chunk creates a multidimensional array; rsort sorts a one dimensional array; you are sorting the chunks instead of what's in them

    PHP Code:
    $pages[$page]; 
    This statement does nothing at all

  3. #3
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well foo bar.... guess I have some thinking to do now lol

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sort then chunk

  5. #5
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    sort then chunk
    lol, it's the smaller things in life....

    thanks, that did the trick!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •