After the foreach use substr to remove the last character:
If the last parameter (lenght) is negative it will remove the characters at the end of the string.
Do not forget to start $regra
otherwise your value will always be reset every time you go.
if (isset($_POST['checkbox'])) {
$regra = '';
foreach ($_POST['checkbox'] as $key => $value) {
$id = mysql_real_escape_string($value);
$regra .= "'{$id}',";
}
$regra = substr($regra, 0, -1);
echo $regra;
}
Another way to format this string at once is to combine the first and last single quotation marks between implode calls:
$arr = array('98602','98603','98604'); // equivalente o $_POST
$novo = "'". implode("','", $arr) ."'";
echo 'implode '. $novo;
Output:
'98602','98603','98604'