Freelancer job part time jobs

  • Home
  • Jobs hiring now
  • FAQ
  • Contact

Switch Statement in PHP – php tutorial

February 1, 2011 by Freelance Leave a Comment

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • More
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • Click to print (Opens in new window)

You have used the “if statement”. But sometimes, this statement can not work properly. At that time we have to use another statement. This is known as switch statement.
A quick way of verifying in PHP is switch statement
Switch statement makes your task easier for you. The way of switch statement is different to other statements. It gets a variable and then verifies it while comparing to all other variables. So, at a time it tests out many statements which is not possible in “if statement”.

An example of switch statement
Here, is an example where we have used the name of different lands. The variable which is used is $target and different cases are America, Italy, Iran, France and Arabian Sea.

$target = "America";
echo "Traveling to $target<br />";
switch ($destination){
    case "Italy":
        echo “Take an Italian pizza";
        break;
    case "America":
        echo "Take something special";
        break; 
    case "Iran":
        echo "Take a nice sweater";
        break; 
    case "France":
        echo "Take many perfumes";
        break;
    case "Arabian Sea":
        echo "Take a swimming suit";
        break; 
}

Exhibit
Traveling to America
Take something special
In the above example, the value was America. By the use of switch statement, a case was searched having the value of America. When the text was displayed, the text from the case was also printed.
All the codes have “break”. It avoids the case from execution. Switch statements are exclusive in their function. if you want to become an expert then you are required a lot of practice.
Default case in Switch statement
You have to know that switch statement has default case as “if statement” contains else section. So, it will give you a good result, if you add default secton in all the switch statements. Here is an example where we have not used any case. Due to that reason, we ought to use default case. One more thing to remember is that default is a main keyword and case does not come previous to default.

$target = "London";
echo "Traveling to $target<br />";
switch ($destination){
    case "Italy":
        echo “Take an Italian pizza";
        break;
    case "America":
        echo "Take something special";
        break; 
    case "Iran":
        echo "Take a nice sweater";
        break; 
    case "France":
        echo "Take many perfumes";
        break;
    case "Arabian Sea":
        echo "Take a swimming suit";
   
                    break;  
    default:
        echo "Take lots of dresses!";
        break;
}

Exhibit:
Traveling to London
Take lots of dresses!

100% Bonus

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Google+ (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • More
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • Click to print (Opens in new window)
How to use Switch Case in C++ programming language
If statement – php tutorial
If else conditional statement – php tutorial
Elseif in PHP – php tutorial
While Loop in PHP – php tutorial
Control Structures in PHP language
For Loop in PHP – php tutorial
Comments in PHP – php tutorial
PHP Echo – php tutorial
SQL Default – SQL tutorial
Freelance Switch Job Board Website Review
Each Loop in PHP – php tutorial
Do While Loop in PHP – php tutorial

Filed Under: PHP

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CAPTCHA
Refresh

*

Earn money as trader

Earn from home ads

Work from home ads

HotForex 50% Bonus

Work from home as instaforex forex trader

instaforex bonus 30%

Freelance categories

  • Earn money as webmaster
    • Advertising
    • Affiliate program
    • Amazon
    • Bidvertiser
    • Blogging
    • Facebook
    • Google Adsense
    • Hosting
    • Komoona
    • LinkedIn
    • Neteller
    • SEO
    • Skrill Moneybookers
    • Twitter
  • Education
    • How to do
    • Job description glossary
    • Wordpress how to do
  • Freelancer advice tips
    • Forex trading from home
      • Affiliate programs
        • 500affiliates
        • Avapartner
        • Etoropartners affiliate program
        • HotForex Affiliate program HFaffiliates
      • Binary options trading
        • Anyoption
        • OptionBit Review
        • TradeRush
        • Ubinary
        • Yesoption
      • Facebook IPO price – buy facebook stock
      • Forex brokers reviews
        • 4XP Review
        • Alpari Russia Review
        • Alpari UK
        • AvaTrade Review
          • AvaFx Review
        • DeltaStock Review
        • Directfx Review
        • DukaScopy Review
        • Easy Forex Review
        • Etoro Review
        • ETX Capital Review
        • Exness
        • Forex.com Review
        • Forex4you
        • ForexYard Review
        • FXCM Review
        • FXDD Review
        • FxOpen Review
        • Fxpro Review
        • HiWayFX review
        • Hotforex Review
        • HY Markets Review
        • IC Markets Forex Review
        • IFC Market
        • IForex Review
        • IG Markets
        • Instaforex Review
        • Ironfx Review
        • Keystock Review
        • LCG review
        • Liteforex broker
        • Marketiva Review
        • Markets.com Review
        • NordFx Review
        • Pepperstone Review
        • Plus500 review
        • Roboforex
        • SwissQuote Bank Review
        • Thinkforex
        • UFX Markets review
        • Windsor Brokers Review
        • XeMarkets Review
        • xForex
        • Xtrade Review
        • Youtrade FX Review
        • Zulutrade Review
    • Freelance glossary
    • Freelance Programming tips
    • Learn about programming
      • C++
      • Linux
      • PHP
      • Ruby on rails
      • SQL
    • Top freelance websites
    • Web Design tips
    • Work from home business
    • Writing tips
  • Freelancer job news
    • Job advice
    • Thinking
    • Worldwide job offers
  • IT news
  • Jobs

Best Forex Brokers Reviews

  • Avafx Review – how to earn in forex market using Avafx Forex Broker
  • Avatrade Review
  • eToro Review
  • Alpari NZ Review
  • InstaForex Review
  • DukaScopy Review – Swiss bank Forex broker
  • Forex.com Review – how to earn money in forex market as trader
  • Ironfx Review
  • FXCM Review
  • FxOpen Review
  • Hotforex Review
  • Markets.com Review
  • UFX Markets Review
  • Zulutrade Review – earn money using free forex signals where forex experts trade for you
  • Exness forex broker Review
  • Fxpro Review
  • LiteForex forex broker review
  • NordFx Review and bonus
  • Roboforex forex broker Review
  • XM.com Review - Xemarkets forex broker review

Navigation

  • Home
  • Jobs hiring now
  • FAQ
  • Contact

Languages

  • Arabic language
  • Bengali language
  • Communiqué de presse
  • China language
  • Pressemitteilung
  • Japanese language
  • Comunicado de imprensa
  • Russian language
  • Presione soltar
  • Turkish
  • Comunicato stampa
  • Hindi language

Recent articles

  • How to earn money as freelancer ?
  • LCG broker Review
  • Forex vs. stocks – Which is a Better for Trading ?
  • Thinkmarkets Review
  • FxPro Review – download FxPro Metatrader – tight spreads
Freelancer job - Copyright 2007
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.