Featured post
php - problem with conditional switch -
the example below extráct http://php.net/manual/de/control-structures.switch.php
<?php $totaltime = 0; switch ($totaltime) { case ($totaltime < 1): echo "that fast!"; break; case ($totaltime > 1): echo "not fast!"; break; case ($totaltime > 10): echo "that's slooooow"; break; } ?>
i expected result "that fast." actual result "not fast!". great if 1 can explain me why?
but if add case, case 0: echo "that super fast!".
echoing properly. i.e "that super fast!". please me how use conditional switch statement.
edit:-
thanks responses. able overcome above problem modifyong switch($totaltime) switch(1)
case ($totaltime < 1):
means 1
php (that equation returns true)
case ($totaltime > 1):
means 0
php (that equation returns false)
since $totaltime
0, output
in other words php compares $totaltime
result of comparisons.
edit regarding edit in op:
you need rid of switch()
-statement. use compare against different values , not use additional expressions it.
i mean wrong with
<?php $totaltime = 0; if ($totaltime < 1) { echo "that fast!"; } else if ($totaltime > 10) { echo "that's slooooow"; } else if ($totaltime > 1) { echo "not fast!"; } ?>
edit: please note switched last 2 if-statements make work.
- Get link
- X
- Other Apps
Comments
Post a Comment