Specifically, they seed phosphorous into the top layer of silicon, which adds extra electrons, with a negative charge, to that layer. Meanwhile, the bottom layer gets a dose of boron, which results in fewer electrons, or a positive charge. This all adds up to an electric field at the junction between the silicon layers. Then, when a photon of sunlight knocks an electron free, the electric field will push that electron out of the silicon junction.