Re: PHP Control Structures The switch construct is generally more than twice as fast at matching a simple integer within a single large set of conditions.
There is largely little difference between the time it takes to find a condition using if,if statements or if-elseif statements. Also the size of the resulting scripts were only negligibly different compared to the difference in execution time.
At first I thought that since the switch statement breaks execution after it matches its value especially since I was using random numbers, that this could account for the time difference, but that also had no bearing. Setting $var=999999 in the below statements had little effect on the faster execution time of the switch statement.
__________________ With,
J. Jeyaseelan Everything Possible |