What potential pitfalls can arise when trying to extract multiple files from different "tar" archives using PHP?

When trying to extract multiple files from different "tar" archives using PHP, potential pitfalls can arise if the file paths overlap or if there are naming conflicts between the files. To solve this issue, you can create a unique directory for each archive and extract the files into their respective directories.

$archives = ['archive1.tar', 'archive2.tar'];
foreach ($archives as $archive) {
    $extractDir = 'extracted_' . pathinfo($archive, PATHINFO_FILENAME);
    mkdir($extractDir);
    exec("tar -xf $archive -C $extractDir");
}