如果所有字段都为空,则在php中验证数组

I have array for uploading photos. I have to validate it for blank values.

 <input type="file" name="photos[]">
 <input type="file" name="photos[]">
 <input type="file" name="photos[]">

If a pic is uploaded in any of 3 fields, It should not throw error else if all the fields are blank, it shld throw error such as "Required at least 1 field.".

Please Note: input field photos[] are dynamically generated with jquery to upload multiple photos at a time. Please Help

May be this can help you to check the file upload from PHP

if (isset($_FILES['photos'])) {
    $photos = $_FILES['photos'];
    $proceed = false;
    foreach ($photos as $photo) {
        if ($photo["error"] <= 0) {
            $proceed = true;
        }
    }
    if (!$proceed) {
        echo "Please upload at least one file";
    }
}

or you can directly use jQuery / Javascript for this before submit the form

Take same id for the array and call check_image() where you want to check . it is not a complete way but this trick will do the needful. Hoping it will do what you need .

<input type="file" id="photo" name="photos[]">
    <input type="file" id="photo" name="photos[]">
    <input type="file" id="photo" name="photos[]">
    <script>
    function check_image()
    {
    if(document.getElementById('photo').value=='')
    {
    alert("please uplaod atleast one image");
    return false;
    }
    else
    {
    return true;
    }
    }
    </script>