What are the advantages and disadvantages of using a foreach loop versus an if statement for processing uploaded files in PHP?

When processing uploaded files in PHP, using a foreach loop is advantageous because it allows you to easily iterate through multiple uploaded files without having to write repetitive code. On the other hand, using an if statement may be more suitable if you only need to perform a specific action based on a condition for each uploaded file. However, using an if statement for processing multiple files can lead to code duplication and decreased readability.

// Using a foreach loop to process uploaded files
if(isset($_FILES['files'])){
    $uploaded_files = $_FILES['files'];

    foreach($uploaded_files['tmp_name'] as $key => $tmp_name){
        $file_name = $uploaded_files['name'][$key];
        $file_size = $uploaded_files['size'][$key];
        $file_type = $uploaded_files['type'][$key];
        
        // Process each uploaded file here
    }
}