How can a multidimensional array be utilized in PHP to maintain a preferred sorting order for file names?

When dealing with file names in PHP, a multidimensional array can be utilized to maintain a preferred sorting order by storing the file names along with their corresponding sort order values. By using this approach, you can easily sort the file names based on the specified order without altering the original file names.

// Define a multidimensional array with file names and their corresponding sort order
$fileNames = array(
    array('name' => 'file3.txt', 'order' => 2),
    array('name' => 'file1.txt', 'order' => 1),
    array('name' => 'file2.txt', 'order' => 3)
);

// Sort the array based on the 'order' key
usort($fileNames, function($a, $b) {
    return $a['order'] <=> $b['order'];
});

// Output the sorted file names
foreach ($fileNames as $file) {
    echo $file['name'] . PHP_EOL;
}