Stumped

Simply not the case. There are tons of places where case statements make sense. Not to mention they are often easier to read than a long set of if/then/else statements.

Again, a matter of opinion. As far as I'm concerned they are nothing more than a awkward if/then/else and I see no point to them.
 


from way up here on my high horse, i will kindly point out that none of you write enough bash scripts to be talking about a "then" clause; such a clause does not exist to you phptards.
 
And your statement is still wrong. Case statements do not and should not re-check their case after a match.

[root@boost ~]# cat asd.php
<?
$dchuck = 'sped';

switch ($dchuck)
{
case 'moron':
echo "true\n";
case 'sped':
echo "truer\n";
case 'fag ruby coder':
echo "truest\n";
}
[root@boost ~]# php asd.php
truer
truest

I realize you're trying to: be funny/be a dickhead/prove me wrong, but your example actually is in support of what I'm saying you god damn tard. Each case can only be true for a single value of switch in your example ("sped"), so there's no risk of more than one case statement firing (which is what I originally said in terms of properly writing a switch/case statement).

I'm very glad I will never have to work with any code you've ever written.
 
I realize you're trying to: be funny/be a dickhead/prove me wrong, but your example actually is in support of what I'm saying you god damn tard. Each case can only be true for a single value of switch in your example ("sped"), so there's no risk of more than one case statement firing (which is what I originally said in terms of properly writing a switch/case statement).

I'm very glad I will never have to work with any code you've ever written.

Are you blind?

root@boost ~]# php asd.php
truer
truest


Seriously not sure how to make it any more obvious to you that TWO case statements fired.
 
Are you blind?

root@boost ~]# php asd.php
truer
truest


Seriously not sure how to make it any more obvious to you that TWO case statements fired.

meh, again, my main language does not require explicit breaks so I just glazed over it. Regardless, you shouldn't be writing ambiguous case statements, otherwise your code would be a bitch to debug should anything go wrong.

If that was a ruby switch statement, it would only fire the middle case statement
 
Wow. I love it when coders fight. It's like watching the Matrix. All I see are green lines.

2qweg75.gif
 
Real quick... using PHP preg_match to try to match portions of a keyword. If said portion matches, I want to assign a value to a variable.

Someone please help. PHP.net and Google have failed me so far.


1. This works.

Code:
<?php

$kw = "http://somesite.com/?a=123&b=345&c=AB932&keyword=123-345-DE";

switch ($kw){
    case (preg_match("/(.*)-AB\z/",$kw)?true:false):
        $tag1 = "49";
        break;
    case (preg_match("/(.*)BC\z/",$kw)?true:false):
        $tag1 = "51";
        break;
    case (preg_match("/(.*)DE\z/",$kw)?true:false):
        $tag1 = "52";
        break;
    case (preg_match("/(.*)FG\z/",$kw)?true:false):
        $tag1 = "53";
        break;
    case (preg_match("/(.*)HI\z/",$kw)?true:false):
        $tag1 = "50";
        break;
    case (preg_match("/(.*)JK\z/",$kw)?true:false):
        $tag1 = "54";
        break;
    default:
        $tag1 = "56";
        break;
}

echo "Tag: " . $tag1 . "\n";

?>

2. That is some ugly code which you wrote. Read what others wrote above me.

3. **crawls away from this thread**