2

I am trying to sort a list of directories according to the contents of a text file within each directory.

So far, I am displaying the list of directories:

$user = $_GET['user'];
$task_list = $_GET['list'];

if ($handle = opendir("../users/$user/tasks/$task_list/"))
{
    $files = array();
    while (false !== ($file = readdir($handle)))
    {
        if ($file != "." && $file != ".." && $file != ".htaccess")
        {
            array_push($files, $file);
        }
    }
    closedir($handle);
}

//Display tasks
sort($files);
foreach ($files as $file)
{
    echo "$file"; 
}

Each directory has a text file within it called due.txt, I would like to sort the list of directories according to the contents of this file due.txt.

So far, I have tried:

$user = $_GET['user'];
$task_list = $_GET['list'];

if ($handle = opendir("../users/$user/tasks/$task_list/"))
{   
    $files = array();   
    $tasksSort = array();
    while (false !== ($file = readdir($handle)))
    {
        if ($file != "." && $file != ".." && $file != ".htaccess")
        {
            $taskSort = file_get_contents("../users/$user/tasks/$task_list/$file/due.txt");
            array_push($files, $file);
            array_push($tasksSort, $taskSort);
        }
        closedir($handle);
    }

    //Sort tasks and display
    sort($tasksSort);
    foreach ($files as $file)
    {
        echo "$file"; 
    }
}

But the $tasksSort array doesn't seem to have any content to sort...?

4

1 回答 1

1
sort($tasksSort);
foreach ($tasksSort as $file)
{
    echo "$file"; 
}
于 2013-02-03T01:47:47.403 回答