Answer:
There are many environmental factors that affect the opening and closing of stomata, mainly water availability.
Stomata regulate gas exchange and water flow. The exchange of carbon dioxide between the plant and the medium is controlled by the opening and closing of stomata. When the stomata open increases the amount of carbon dioxide that enters the plant, but also the amount of water loss increases. For this reason during the night the stomata are closed to avoid unnecessary loss of water.
In dry ecosystems the leaves have fewer stomata to reduce the loss of
water generated by high temperatures.