将数据存储在关联数组php中

I have this code here:

<?php while($rowequipment = mysql_fetch_assoc($sqlequipment)) {
echo '<input type="checkbox" name="equipment[]" value="'.$rowequipment['equipmentid'].'"/>    <input type="text" name="count[]" id="count[]" size="3" value=""/>'
.$rowequipment['description']."<br />";
}?>

This creates a list of checkboxes to select which equipment the user wants and text boxes to put in the number required.

Is it possible to somehow store the data in an associative array in php so that i cant then transfer this into a database? for example:

equipmentid    count
1              2
3              1

Or is there a different way to do this.

Thanks.

You can do:

<form method="post">
<?php
$row[0]['equipmentid'] = 1;
$row[0]['description'] = "test1";
$row[1]['equipmentid'] = 2;
$row[1]['description'] = "test2";

foreach($row as $rowequipment)
{
    $e_id = $rowequipment['equipmentid'];
    echo '<input type="checkbox" name="equipment['.$e_id.'][id]" value="'.$e_id.'"/> ';
    echo '<input type="text" name="equipment['.$e_id.'][count]" id="count'.$e_id.'" size="3" value=""/> ';
    echo rowequipment['description']."<br />";
}
?>
<input type="submit" value="aa"/>
</form>

and the result will be:

array(1) {
  ["equipment"]=>
  array(2) {
    [1]=>
    array(2) {
      ["id"]=>
      string(1) "1"
      ["count"]=>
      string(1) "4"
    }
    [2]=>
    array(2) {
      ["id"]=>
      string(1) "2"
      ["count"]=>
      string(1) "6"
    }
  }
}

now change the foreach with your while and you will have the same result.

PHP will parse form values that use the square brackets and it will also work using IDs so assuming you don't actually need both checkboxes you can have:

echo '<input type="text" name="count['.$rowequipment['equipmentid'].']" ';
echo 'id="count['.$rowequipment['equipmentid'].']" size="3" value=""/>';
echo $rowequipment['description']."<br />";

Note there are no quotes around the id within the square brackets in the HTML.