PHP Switch case behavior: ranges

Would it be so bad to have ranges for switch cases?

...
switch($var)
	{
	case < = 9:
		{
		echo "less than ten";
		break;
		}
	case 10:
		{
		echo "ten exactly";
		break;
		}
	case >10 <> <15:
		{
		echo "a range of values? why not?";
		break;
		}
	case >= 15:
		{
		echo "greater than or equal to fifteen";
		break;
		}
	default:
		{
		echo "what am I not thinking of here?"
		break;
		}
	}
...
Bookmark and Share

Story pulse

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1 AND post_id = 932 GROUP BY hit_date' at line 5]
SELECT SUM(hit_count) AS hits, hit_date FROM WHERE 1=1 AND post_id = 932 GROUP BY hit_date


4 Comments

  1. Marc Cabrera:

    Actually this won’t work, just tested. Try this instead:

    switch ( True ) {
    case ($tmpVar == 729 && $intVal<= 20):
    echo 21;
    break;
    case ($tmpVar == 829 && $intVal<= 20):
    echo 22;
    break;
    case ($tmpVar == 729 && $intVal <= 40):
    echo 40;
    break;
    }

  2. suzza:

    switch($var)
    {
    case $var10 <15: though…

  3. suzza:

    switch($var)
    {
    case $var<=9:
    {
    echo “less than ten”;
    break;
    }

  4. steve cooley:

    nicely done. :)

Leave a comment