Hate for a necro message that already answered, but I'm rather puzzled, no one has touched the switching method (the truth).
There is no real speed advantage in the world of any method
In some cases, the switch was faster, others - if, but faster, but only a fraction of microseconds (48.16 ΞΌs versus 49.11 ΞΌs faster than if).
EDIT
And now I see that OP did the same ...
<?php for ( $totaltime = 0; $totaltime < 11; $totaltime += 0.5 ) { switch ( true ) { case ( $totaltime < 1 ): echo $totaltime . " That was fast!\n"; break; case ( $totaltime < 10 ): echo $totaltime . " Not fast!\n"; break; default: echo $totaltime . " That slooooow\n"; break; } }
Results: https://3v4l.org/d71lZ
0 That was fast! 0.5 That was fast! 1 Not fast! 1.5 Not fast! 2 Not fast! 2.5 Not fast! 3 Not fast! 3.5 Not fast! 4 Not fast! 4.5 Not fast! 5 Not fast! 5.5 Not fast! 6 Not fast! 6.5 Not fast! 7 Not fast! 7.5 Not fast! 8 Not fast! 8.5 Not fast! 9 Not fast! 9.5 Not fast! 10 That slooooow 10.5 That slooooow
fyrye
source share