I know this may be simple question but want to know every ones opinion on this.
what is the difference between switch and IF function in PHP?? What I can see is where ever “switch” function uses “IF” function also applies there..correct me if I am wrong..
Or any performance wise difference between two??
Forget about the performance difference on this level- there may be a microscopic one, but you’ll feel it only when doing hundreds of thousands of operations, if at all.
switchis a construct for better code readability and maintainability:is mostly much more clean and readable than
Edit: Inspired by Kuchen’s comment, for completeness’ sake some benchmarks (results will vary, it’s a live one). Keep in mind that these are tests that run 1,000 times. The difference for a couple of
if‘s is totally negligeable.