This technique will only work with simple backgrounds, but it is a great way of masking detailed hair.
Start by placing the image you want to mask over your background image.

Now select your subject layer (zendaya) and then select the Selection Tool (W)
With the Selection Tool selected, you will now see an option at the top of your Photoshop window that says Select and Mask...

Click Select and Mask... and then click Select Subject. On the right hand side you will see View Mode. In the View drop down box, select Onion Skin and turn the Transparency up to 100%. You also have two Refine Modes available. Color Aware and Object Aware. Try selecting the different modes to see which works best with your image. I am using Object Aware

Back up at the top of your screen, you will notice an option called Refine Hair. Try selecting this. If it doesn't improve the hairs mask, press CTRL/CMD Z to undo.
Most likely there will still be a lot of the background showing through the hair. So now we need to refine the hair selection, and remove the background that is showing through.
Select the Refine Edge Brush Tool ( R) and make sure the + symbol is selected as well as a soft brush. You can experiment with different brush sizes and softness.

Now select a dominant piece of the background showing through the hair by left clicking and holding down your mouse button. With your left mouse button still selected, draw across the edge of the hair. Any of the background layer that is of the same colour and brightness as your selection will be erased.

Now change the View Mode to Overlay. Repeat the step above with any more background that you can see.
When you are happy with the results, click OK. Now select Add layer mask, in your Layers window

The mask will now be added, but the results may still not be perfect.

If some of the background is still showing, create a new layer above your subject and clip it to your subject layer (Right click on the new layer and select Create Clipping Mask). Name it something like Hair Fill. Now select your Brush Tool (B) and reduce the brush opacity and flow rate. Select a darker colour from your subjects hair, by holding ALT to bring up your Eye Dropper Tool.

Now gradually paint over the parts of the hair that are still showing the background, until you can no longer see the background though the hair.

Once you are happy with your results, select your subject and hair fill layers, and turn them into a Smart Object. Now you can make your usual adjustments to blend the masked image with the background.