This study proposes novel three-dimensional (3D) matrices of wavelength/time/spatial code for code-division multiple-access (OCDMA) networks, with a double balanced detection mechanism. We construct 3D carrier-hopping prime/modified prime (CHP/MP) codes by extending a two-dimensional (2D) CHP code integrated with a one-dimensional (1D) MP code. The corresponding coder/decoder pairs were based on fiber Bragg gratings (FBGs) and tunable optical delay lines integrated with splitters/combiners. System performance was enhanced by the low cross correlation properties of the 3D code designed to avoid the beat noise phenomenon. The CHP/MP code cardinality increased significantly compared to the CHP code under the same bit error rate (BER). The results indicate that the 3D code method can enhance system performance because both the beating terms and multiple-access interference (MAI) were reduced by the double balanced detection mechanism. Additionally, the optical component can also be relaxed for high transmission scenery.