I have a script generating a form with a varying number of checkbox fields. This is for an item/category setup, and the number of categories (and their ids) varies depending on various factors.
So the form might have:
<input type="checkbox" name="category12" value="checked" />Category 12<br />
<input type="checkbox" name="category13" value="checked" />Category 13<br />
<input type="checkbox" name="category26" value="checked" />Category 26<br />
and so on - basically any number of checkboxes.
At the moment I'm doing the following clunk:
for ($i=1; $i<=99; $i++) {
if ($_POST['category' . $i]) {
$categorylist[] = $i ;
}
}
which is a ridiculously brute-force way of doing it. What I want to do is say "for every element in the $_POST array whose key starts with "category" followed by a number, do something with the number".
Any ideas?