On an RPi, wifi is controlled by /etc/wpa_suplicant/wpa_suplicant.conf. Here is an example from one of my Pi Zero Ws:
---------------------------------->8?? 8<-----------------------------------------
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
?? ?ssid="Home Network"
?? ?psk="some-password"
?? ?priority=2
}
network={
?? ?ssid="TAEiPhone"
?? ?psk="some-other-passwrd"
?? ?priority=1
}
---------------------------------->8?? 8<-----------------------------------------
Each network you want your system to potentially use is in a network={} definition. ssid is the name of the network and psk is the password. Note that my home network is a higher priority. This Pi Zero will first try to connect to my home network. If it's not available, then it will try my iPhone. If you don't specify a priority, that network's value will be 0. I believe the assigned priority can even be a negative number, if you want.
PS. If you're building a new "headless" image for a Pi Zero W, you can put your wpa_supplicant.conf in the /boot directory, along with an empty file called "ssh". Then, on first boot, the OS will move the wpa_supplication.conf file to the correct location and enable ssh. In this way you can build an RPi Zero W without ever having to hook up a monitor and keyboard.