How to remove the last two commas in an array after using the implode function?
There are two ways to remove commas:

trim() only removes spaces, so to trim commas as well you need to add what characters it should trim (commas and spaces in this example)

$doctors = trim($doctors, ", ");

Or you could remove empty entries from the array before imploding it using array_filter()

$doctors = array_filter($_POST['doctors']);
Write
×