After the foreach use replace to remove the last character:
If last parameter(lenght) is negative it will remove the characters at the end of the string.
Don’t forget to start $regra
otherwise its value will always be 'reset' with each round of the.
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 simple quote between implode call:
$arr = array('98602','98603','98604'); // equivalente o $_POST
$novo = "'". implode("','", $arr) ."'";
echo 'implode '. $novo;
Exit:
'98602','98603','98604'
It is not the array that returns the comma at the end, my friend. It is the string you are using
– Wallace Maxters