Mg is a metal that has 12 atomic numbers and thus its electronic configuration is . The outer most shell of this element has 2 electrons so it loses 2 electrons and thus form ions. Br is a nonmetal and has 35 atomic number so its electronic configuration is . Since its outermost shell has 7 electrons so it can accept one electron and thus forms . So magnesium ion and bromide ion combine and forms an ionic compound .
P is also a nonmetal and combine with Br with covalent bond and due to electronegativity differences form polar covalent compound such as .