Reconstructing the galaxy density field with photometric redshifts - II. Environment-dependent galaxy evolution since z ≃ 3