This paper presents an iterative algorithm for the synthesis of the three-dimensional (3D) radiation pattern generated by an antenna array of arbitrary geometry. The algorithm is conceived to operate in fifth-generation (5G) millimeter-wave scenarios, thus enabling the support of multi-user mobile streaming and massive peer-to-peer communications, which require the possibility to synthesize 3D patterns with wide null regions and multiple main beams. Moreover, the proposed solution adopts a phase-only control approach to reduce the complexity of the feeding network and is characterized by a low computational cost, thanks to the closed-form expressions derived to estimate the phase of each element at the generic iteration. These expressions are obtained from the minimization of a weighted cost function that includes all the necessary constraints. To finally check its versatility in a 5G environment, the developed method is validated by numerical examples involving planar and conformal arrays, considering desired patterns with different numbers of main beams and nulls.