PPIs can definitely affect magnesium. https://www.gov.uk/drug-safety-update/proton-pump-inhibitors...
On the other hand if your heartburn causes reflux then the PPI can help sleep. https://www.ncbi.nlm.nih.gov/pubmed/24942514