如何在PHP中验证这些元素?

I have checkboxes with the following names:

chk-cloud-a
chk-cloud-b
and so on...

chk-dco-a
chk-dco-b
and so on...

How do I validate after form submission such that:
Atleast one element from the checkboxes with name starting with chk-cloud or chk-dco must be ticked?

I hope someone can help me with this.

Cheers!

If they're checkboxes then all you really care about is whether or not they have a value. What that value is is not significant.

All you need to do is check that there are elements in the $_GET or $_POST (depending on form submission method) that contain fields of that name.

if (array_key_exists ('chk-cloud-a ', $_POST)) {
    // Do what should happen of that checkbox is checked
}

If the problem is that you have multiple similar checkboxes then you might want to consider grouping them together in an array. This is done by using square bracket notation in the field name:

<input type="checkbox" value="1" name="chk-cloud[a]" />
<input type="checkbox" value="1" name="chk-cloud[b]" />
<input type="checkbox" value="1" name="chk-cloud[c]" />
<input type="checkbox" value="1" name="chk-cloud[d]" />

You can use a loop to process such a group

foreach ($_POST [chk-cloud] as $key => $value) { // We're really only interested in the key
    handleCheckbox ($key) // handleCheckbox is some function you've wrote
}

Or

foreach (array_keys ($_POST [chk-cloud]) as $key) { // Logically the same as above

Just use preg_match or strpos to check if any key in POST matches Your requirements. Personally i would make subarray of these elements and just check if its empty.

try like this:

function checkBoxValidate(){ //method to test checkbox
$array = array('a','b','c','d', ....); // make array for each checkbox name
foreach ($array as $a){
    if((isset($_REQUEST['chk-cloud-'.$a]) || isset($_REQUEST['hk-dco-'.$a])) &&  ($_REQUEST['chk-cloud-'.$a] == 'check_value' || $_REQUEST['hk-dco-'.$a] == 'check_value' ) ){
     return true;
    }
}
return false; //return no check box was checked
}