I think you are after something like:
foreach ($pieces as $piece) {
if (file_exists($piece . '.zip')) {
echo '1';
} else {
echo '2';
}
}
Or perhaps run a filter on the array, to obtain a list of files that exist, such as:
$existingFiles = array_filter(
$pieces,
function ($piece) { return file_exists($piece . '.zip'); }
);