Forum Moderators: coopster
(1)
if (something) {
// action;
} else if (something else) {
// another action;
} etc etc
(2)
switch($var) {
case('something'):
// action;
break;
case('something else'):
// another action;
break;
etc etc
}
Is there a difference? Any advice appreciated.
Patrick
anyway, if you are concerned with the server and execution speed then the execution time difference between these two must be very very small.
So if you need and else then use switch default: and it will be very slightly faster. However unless you are actually looping through 1000's of then an increase in speed of 1/10000 second per iteration is not likely to make any difference :)
I prefer switch as it is easier to read. Nothing to do with speed.