How long your iPhone will last depends on a number of factors.
If you’re purchasing the latest iPhone, you can expect it to last at least 6 years with basic care and handling. You can extend its life further by using a good quality case to protect it from accidental damage and drops.
In addition, Apple provide at least 6 years of iOS updates from the initial release date of each iPhone. It is important you have the latest iOS version as it will have important security updates that can protect you from hackers and other vulnerabilities.
Furthermore, an iPhone battery will suffer from health degradation over time. The more you use your iPhone, the more you will need to charge it, with each charge cycle gradually decreasing the health of your battery. However, Apple have made improvements in its software in order to automatically optimise the best time to charge your iPhone. This can temporarily mitigate and extend the life of your iPhone's battery.