I have a function that concatenates a query from POST variables, this I do with a foreach:
$id = $_POST['empId'];
$query = "UPDATE userInfo SET ";
foreach ($_POST as $key => $value) {
$query .= "$key = '$value', ";
}
$query .= " WHERE id = '$id'";
How can I know when is the last iteration to be able to remove the final comma in the last iteration and thus be able to construct the query correctly?