Or any performance difference between the two ??
Forget about the difference in performance at this level - it may be microscopic, but you will only feel it when doing hundreds of thousands of operations, if at all. switch- this is a design for better readability of the code and maintainability:
switch ($value)
{
case 1: .... break;
case 2: .... break;
case 3: .... break;
case 4: .... break;
case 5: .... break;
default: .... break;
}
basically much cleaner and more readable than
if ($value == 1) { .... }
elseif ($value == 2) { .... }
elseif ($value == 3) { .... }
elseif ($value == 4) { .... }
elseif ($value == 5) { .... }
else { .... }
: Kuchen, - ( , ). , , 1000 . if .
- if elseif ( ==) 174
- if, elseif else ( ==) 223
- if, elseif else ( ===) 130
- switch/case 183
- switch/case/default 215
( phpbench.com):
/case if/elseif . , === ( ) , == ().