I believe that to create an array, you must use brackets following the name.
Code:
<form name="yourform" action="formresults.php" method="post">
<input type="checkbox" name="alotofcheckboxes[]" value="1" />
<input type="checkbox" name="alotofcheckboxes[]" value="2" />
<input type="checkbox" name="alotofcheckboxes[]" value="3" />
<input type="checkbox" name="alotofcheckboxes[]" value="4" />
<input type="checkbox" name="alotofcheckboxes[]" value="5" />
<input type="checkbox" name="alotofcheckboxes[]" value="6" />
<input type="checkbox" name="alotofcheckboxes[]" value="7" />
<input type="checkbox" name="alotofcheckboxes[]" value="8" />
<input type="checkbox" name="alotofcheckboxes[]" value="9" />
<input type="checkbox" name="alotofcheckboxes[]" value="10" />
<br><br>
<input type="button" value="Create array"
</form>
If you want to display the array on a new/different page, make that different page your "action" and put the following on that page where you want the array to appear:
Code:
<?php
$array=$_POST["alotofcheckboxes"];
print_r ($array);
?>
If you want to display the results to the same page your form is on, make that same page your "action and again, put that code on that page where you want the array to appear.
If you wanted to display an output like:
Array(1, 4, 7)
You'd put this where you want it to display:
Code:
<?php
$array=$_POST["alotofcheckboxes"];
echo "Array(".$array[0];
array_shift($array);
foreach ($array as $value)
{
echo ", ".$value;
}
echo ")"; ?>
If 1, 4, 5, 7 and 9 have been checked the output that the code would produce:
Array(1, 4, 5, 7, 9)
There are a lot of ways to manipulate the display of the values.
There's the php function count() that will give you the number of elements in your array. You could display something like: "1, 4, 5, 7 and 9" by using $last=count($array), using array_shift($array) and array_pop($array), again using a foreach ($array as $value) statement and trailing an echo "and ".$array[$last] at the end.
I'm not that far into it, but it might be possible and simpler to use a while loop instead of array_shift and array_pop and the foreach function.
This is all assuming you may want to use php instead of js. There are a lot of advantages in using php.
w3schools has some good tutorials and more importantly, a chart of php functions and constants.
Edit: probably an easier way would be to use a php while statement and i=i++ to name your array items "$item1", "$item2", etc. Then it would be easier to echo them in whatever configuration you want with whatever punctuation you want without all the shifting and popping. I'm still learning and don't have much time right now, but maybe one of the php guys here could supply the code for that.
What are you using the array for?