Why does my switch automatically output the first case?-PHP Chinese Network Q&A
Why does my switch automatically output the first case?
MArtian
MArtian 2019-11-16 16:13:12
0
2
1154
$init = $_GET['score']; switch($init){ case $init >=90 : echo '

厉害了,我的学霸!

'; break; case $init >=80 : echo '

再接再厉,努力吧!

'; break; case $init >=70 : echo '

差太多啦!得加油赶上了!!

'; break; case $init >=60 : echo '

建议你留级吧!!

'; break; default: break; }

1.png

Obviously no parameters have been passed to the form yet, so how come the first case is output? At this time, the $init variable is empty. How can it be judged successful? ? What's going on? ?

MArtian
MArtian

reply all (1)
卢小强

If you submit without inputting anything, the submitted value will be empty. Empty does not meet any switch conditions, so it will start execution from the first CASE and will not stop until it encounters break

  • reply Will switch run even if the conditions are not met? That's it, thank you
    MArtian author 2019-11-17 12:41:30
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!