How can PHP distinguish between multiple file inputs with dynamic names in a form?

When dealing with multiple file inputs with dynamic names in a form, PHP can distinguish between them by using array notation in the input field names. By naming the file inputs as an array (e.g. "file[]"), PHP will automatically create an array of files when the form is submitted. This allows you to loop through the array in your PHP code to process each file individually.

<form method="post" enctype="multipart/form-data">
    <input type="file" name="files[]" multiple>
    <input type="file" name="files[]" multiple>
    <input type="submit" name="submit">
</form>

<?php
if(isset($_POST['submit'])) {
    $files = $_FILES['files'];
    
    foreach($files['name'] as $key => $name) {
        $tmp_name = $files['tmp_name'][$key];
        // Process each file here
    }
}
?>