I have learnt that phosphorus and sulfur have valences 3, 5 and 2, 4, 6 respectively because of vacant d orbitals. But how?
Phosphorus' configuration is $\mathrm{[Ne]3s^23p^3}$. There are 3 unpaired electrons that can get paired with bonds, so 3 makes sense (similar to nitrogen) and a similar argument for 2 with sulfur (similar to oxygen), but how do the vacant d orbitals help in giving valence 5?
Do 2 electrons from the s orbitals go to the d orbitals and then there are 5 unpaired electrons available for bonding and similarly for sulfur?