Reply
Using ! operator in switch statement
Old 05-22-2008, 10:04 AM Using ! operator in switch statement
KkillgasmM's Avatar
Ultra Talker

Posts: 381
Name: El Phantasmo
Location: England, north west
How would I create a switch statement equivalent to the following?

PHP Code:
<?php
if (!$_GET['value']) {
$variable 'something'; }

else {
$variable 'somethingElse'; }
?>
Thanks.
__________________
New Portfolio
KkillgasmM is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-22-2008, 10:39 AM Re: Using ! operator in switch statement
tripy's Avatar
Fetchez la vache!

Posts: 2,131
Name: Thierry
Location: In the void
Don't use a case statement. Case can only operate on an instantiated variable.
Use the if shorthand rather
PHP Code:
$variable=(isset($_GET['value'])?'something':'nothing'
Explaination:
$variable=({test returning true or false}?{value if true}:{value if false};
__________________
Listen to the ducky: "This is awesome!!!"

tripy is offline
Reply With Quote
View Public Profile
 
Old 05-22-2008, 07:32 PM Re: Using ! operator in switch statement
KkillgasmM's Avatar
Ultra Talker

Posts: 381
Name: El Phantasmo
Location: England, north west
Cool. The code I was using was quite different to the one in my example so I ending up solving it like this:
PHP Code:
    if ($_GET['contactStatus'])
        {
            
$contactStatus $_GET['contactStatus'];
            switch (
$contactStatus)
                {
                    case 
'0':
                    
displayDefault ();
                    break;
                    
                    case 
'1':
                    echo 
"Some of your information was invalid. Please ensure that You have filled valid information into each of the input fields.";
                    break;
                    
                    case 
'2':
                    echo 
"Your message has been sent successfully. We'll get back to you as soon as possible.";
                    break;
                    
                    case 
'3':
                    echo 
"There was an error processing your message. Please try again or use one of our alternate contact methods.";
                    break;
                }
            } 
Thanks!
__________________
New Portfolio
KkillgasmM is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Using ! operator in switch statement
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11797 seconds with 12 queries