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...?

1

1 Answer 1

1
sort($tasksSort);
foreach ($tasksSort as $file)
{
    echo "$file"; 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.