Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using ! operator in switch statement
Old 05-22-2008, 09:04 AM Using ! operator in switch statement
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
How would I create a switch statement equivalent to the following?

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

else {
$variable 'somethingElse'; }
?>
Thanks.
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 05-22-2008, 09:39 AM Re: Using ! operator in switch statement
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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};
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-22-2008, 06:32 PM Re: Using ! operator in switch statement
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
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!
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Reply     « Reply to Using ! operator in switch statement
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.12286 seconds with 12 queries