将单个复选框值指定为数组

Is there a way of assigning the value of a checkbox as an array.

I have a load of checkboxes, one of which is an all option. I would like to set the value of this to an array?

I have tried creating an array of ints (ids) from an array of my objects using a simple loop and then using print_r in the value (I know this is a bit ugly and I can see why this wouldn't work but can't seem to find the correct syntax).

$arrAllID = array();
foreach ($AvailableGroups as $objASRDCallBackGroup)
{
    $arrAllID[] = $objASRDCallBackGroup->m_iGroupID;
}

<input id="group-name" value="<?php print_r($arrAllID) ?>" name="SelectedGroups[]" type="checkbox">All

Also I could design around this and do the retrieval of the collection when the form is posted by checking if all was selected or something but I would really like to know how you can do this now..

Any help greatly received.

Thanks

You can use the HTML5 data attribute to store your array of values. I'm not very familiar with PHP, but the data attribute will render on the client, and if this checkbox is clicked, you can loop through the array in the data attribute and do whatever you need to send data back to the server.

<input id="group-name" data-allid="<?php print_r($arrAllID) ?>" name="SelectedGroups[]" type="checkbox">All

function someClickHandler() {
     var chkGroupName = document.getElementById('group-name');
     var allIds = chkGroupName.attr('data-allid');
    // do what you need with the array of ids.
}