What is the function of potassium citrate and magnesium citrate. Please elaborate?

Different. Magnesium citrate is used as a laxative while potassium citrate is used to alkalinize the urine and make it less acidic. Each is a citrate but each has very different functions.
It is the citrate. Both provide citrate to the body which goes to the urine preventing stone formation in people who are deficient in urinary citrate. Whether potassium or magnesium is used it has sometimes to do with your blood level of either or accompanying meds interaction. Also, low magnesium level in urine may increase stone formation. If this is the case, mag citrate may be preferable.