I don't know how your HTML is built, but let you have these checkboxes:
<input type="checkbox" name="check[]" value="a" /> <input type="checkbox" name="check[]" value="b" /> <input type="checkbox" name="check[]" value="c" /> <input type="checkbox" name="check[]" value="d" /> <input type="checkbox" name="check[]" value="e" />
In this case, if all of them are sent, $ _POST ['check'] will contain 0 => a, 1 => b, etc.
If only the first and last are checked, you will have 1 => a, 2 => e, and you will need to see which ones are not marked (b, c, d)
My solution is as follows:
Get all checkboxes from HTML and compare with published ones:
$doc = new DOMDocument(); $doc->loadHTMLFile('test6.php'); $cboxes = $doc->getElementsByTagName('input'); foreach ($cboxes as $cbox) { if($cbox->getAttribute('type') == 'checkbox') { $cb[] = $cbox->getAttribute('value'); } } $differences = array_diff($cb, $_POST['check']); var_dump($differences);
If a and e sent, this will output:
array (size=3) 1 => string 'b' (length=1) 2 => string 'c' (length=1) 3 => string 'd' (length=1)
I forgot to mention that it can also track the difference in the keys of the array, and not just the values, for example, if b and c are placed (1 and 2 keys), the output will be:
array (size=3) 0 => string 'a' (length=1) 3 => string 'd' (length=1) 4 => string 'e' (length=1)
therefore, unpublished keys are 0.3.4
$differences = array_diff($cb, $_POST['check']); var_dump($differences); // unposted checkboxes with relevant keys $diff1 = array_diff($cb,$differences); var_dump($diff1); // posted checkboxes with relevant keys