The electroplating wastewater containing various metal ions was treated by adding sodium dodecyl benzene sulfonate (SDBS) and regulating pH value, and the resulting precipitates were characterized by X-ray diffraction (XRD). The results showed that organic anions intercalated layered double hydroxides (OLDHs) and inorganic anions intercalated layered double hydroxides (ILDHs) were in-situ formed to remove heavy metals during the treatment process. In order to reveal the formation mechanism of the precipitates, SDB− intercalated Ni–Fe OLDHs, NO3− intercalated Ni–Fe ILDHs and Fe3+-DBS complexes were synthsized by co-precipitation at various pH values for comparison. These samples were characterized by XRD, Fourier Transform infrared (FTIR), element analysis as well as the aqueous residual concentrations of Ni2+ and Fe3+ were detected. The results showed that OLDHs with good crystal structures can be formed as pH≤7, while ILDHs began to form at pH = 8. When pH < 7, complexes of Fe3+ and organic anions with the ordered layered structure were formed firstly, and then with increase in pH value, Ni2+ inserted into the solid complex and the OLDHs began to form. However, Ni–Fe ILDHs were not formed when pH ≤ 7. The Ksp (Solubility Product Constant) of OLDHs was calculated to be 3.24 × 10−19 and that of ILDHs was 2.98 × 10−18 at pH = 8, which suggested that OLDHs might be easier to form than ILDHs. The formation process of ILDHs and OLDHs were also simulated through MINTEQ software, and the simulation output verified that OLDHs could be easier to form than ILDHs at pH ≤ 7. Information from this study provides a theoretical basis for effective in-situ formation of OLDHs in wastewater treatment.