根据选中的复选框存储数组元素?

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

Below you can see an overview of my goal. I am displaying my check boxes in a for loop.

Here I am getting the all values in an array, but I want store the array elements based on the check box checked.

<?php 
    $j=0;
    $arr = Array();
foreach($collection as $data) {  
    $mageid=$data['mageproductid'];
    $products = Mage::getModel('catalog/product')->load($mageid);
    $productMediaConfig = Mage::getModel('catalog/product_media_config');       
    $checkeven=0;
        $arr[$j]=$products->getId();
        //echo $arr[$j];
    $j++;
} ?>

My checkbox code:

 <form id="check_all" action="" method="POST" name="check" >
<input type="checkbox" class="multid[]" id="<?php echo $products->getId();?>"  value="checked" />  </form>

What do I have to do in order to get checked values in my array? Did I do anything wrong?

After submiting the form you can get an array of checked products with $_POST['multid']

Use input name attribute

<input type="checkbox" name="multid[<?php echo $products->getId();?>]" value="checked" />

No in you php code, check if multid[yourProductId] is set, and store them if it is set.

<?php 
$j=0;
$arr = Array();
foreach($collection as $data) {  
$mageid=$data['mageproductid'];
$products = Mage::getModel('catalog/product')->load($mageid);
$productMediaConfig = Mage::getModel('catalog/product_media_config');       
$checkeven=0;
$arr[$j]=$products->getId();
if(!empty($_GET['multid['.$arr[$j].']']))
  its checked, do something.
//echo $arr[$j];
$j++;
} ?>

Can you use javascript? Try this one.
HTML:

<input type="hidden" id="hdnCheckedIDs" value="" />

Before submit, on submit button's client click, Javascript:

var CheckedIDs = "";
for each checkbox
    if(document.getelementbyid('multid1').checked)
        CheckedIDs = CheckedIDs + document.getelementbyid('multid1').id;
document.getelementbyid('checkboxID') = CheckedIDs;

In PHP, you can use this comma seperated string $_POST['hdnCheckedIDs'] to get the IDs of checked chekboxes.