Use the code below. It's in the manual under variable variables somewhere if you need more info.
for ($i=1; $i<8; $i++)
{
$variable_name = "a".$i+1;
if ($$variable_name)
{
$num_filled_fields++;
}
}
Note that to do the for loop 7 times starting with 1, you need to check that the index is less than 8, not 7.
Hope that helps,
Jamie.