What are common methods for sorting and displaying different file extensions in PHP?

When working with files in PHP, it is common to need to sort and display files based on their file extensions. One way to achieve this is by using the `glob()` function to retrieve a list of files matching a specific pattern, then sorting them based on their extensions using a custom sorting function. Finally, you can display the sorted files in a list or table format.

// Retrieve a list of files matching a specific pattern
$files = glob('path/to/files/*');

// Custom sorting function to sort files based on their extensions
usort($files, function($a, $b) {
    $extA = pathinfo($a, PATHINFO_EXTENSION);
    $extB = pathinfo($b, PATHINFO_EXTENSION);
    return strcmp($extA, $extB);
});

// Display the sorted files
echo '<ul>';
foreach ($files as $file) {
    echo '<li>' . $file . '</li>';
}
echo '</ul>';