Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Some odd problems with switch case

$
0
0

Ok so i have a few rather odd problems with switch case. I have no clue why these things are happening:

  PAR IS: <?php

        $par = isset($_GET['par'])?$_GET['par'] : ''; 
    switch ($par) {

    case $par >=0 && $par <=2:
        echo 'par 0-2';
		echo '<br/> PAR: '.$par;
        break;
    case $par >=3 && $par <=5:
        echo 'par 3-5';
		echo '<br/> PAR: '.$par;
        break;
    case $par >=6:
        echo 'par >=6';
		echo '<br/> PAR: '.$par;
        break;
    default:
        echo 'ERROR: invalid PAR score passed. Please contact server administrator';
    }
?>

if par >=1 the script works no problems BUT

 

1) if par is 0 echos 'par 3-5 PAR: 0' rather than 'par 0-2 PAR: 0' this seems very odd as 1 and 2 work  fine!

2) if there is no value for par, it returns 'par 3-5 PAR: ', not default message

 

These problems seem very odd to me. does anyone have a clue why this is happening??

 

Thanks in advance for any replies!


Viewing all articles
Browse latest Browse all 13200

Trending Articles