Switch Statements in PHP

Switch Statement in PHP

The switch statement is similar to a series of if statements on the same expression.

<?php

$i=0;

switch ($i)

{

case 0:

echo “$i equals 0″.”<br/>”;

break;

case 1:

echo “$i equals 1″.”<br/>”;

break;

case 2:

echo “$i equals 2″.”<br/>”;

break;

}

?>

Another Example:

<html>

<form method=”post”>

Enter first number<input type=”text” name=”f”/><br/>

Enter second number<input type=”text” name=”s”/><br/>

Enter your choice<input type=”text” name=”ch”/><br/>

<input type=”submit” value=”Calculate Now”/>

</form>

<?php

$f=$_POST[‘f’];

$s=$_POST[‘s’];

$choice=$_POST[‘ch’];

switch ($choice)

{

case “+”:

$sum=$f+$s;

echo “Sum=”.$sum;

break;

case “-“:

$sub=$f-$s;

echo “Subtraction=”.$sub;

break;

case “*”:

$mult=$f*$s;

echo “Multiplication=”.$mult;

break;

case “/”:

$div=$f/$s;

echo “Division=”.$div;

break;

default:

echo “Invalid choice”;

}

?>

</html>

for read complete php buy our 2nd edition PHP Mysql for advanced learning book online at

PHP MYSQL – FlipKart  Amazon  Google PlayStore   International 

Publisher : FSP Publication    ISBN : 978-1-61813-325-0 (6 May 2016)

89 thoughts on “Switch Statements in PHP

  1. Hey there! This is my first comment here so I just wanted to give a quick shout out and tell you I genuinely enjoy reading through your articles. Can you suggest any other blogs/websites/forums that cover the same subjects? Thanks a lot!|

  2. Excellent beat ! I wish to apprentice while you amend your site, how can i subscribe for a weblog web site? The account aided me a applicable deal. I have been a little bit acquainted of this your broadcast offered brilliant clear concept|

  3. Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your site? My website is in the exact same area of interest as yours and my visitors would truly benefit from a lot of the information you present here. Please let me know if this okay with you. Thanks a lot!|

  4. Hi are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and create my own. Do you need any coding knowledge to make your own blog? Any help would be greatly appreciated!|

  5. Hey there terrific website! Does running a blog like this require a great deal of work? I’ve very little expertise in programming but I was hoping to start my own blog soon. Anyway, if you have any suggestions or techniques for new blog owners please share. I understand this is off topic nevertheless I simply needed to ask. Thanks a lot!|

  6. Hi would you mind sharing which blog platform you’re working with? I’m going to start my own blog in the near future but I’m having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S My apologies for being off-topic but I had to ask!|

  7. Hey there! I just wanted to ask if you ever have any trouble with hackers? My last blog (wordpress) was hacked and I ended up losing many months of hard work due to no backup. Do you have any solutions to stop hackers?|

  8. Hey! This post couldn’t be written any better! Reading this post reminds me of my good old room mate! He always kept chatting about this. I will forward this write-up to him. Fairly certain he will have a good read. Thank you for sharing!|

  9. Excellent blog you have here but I was curious if you knew of any user discussion forums that cover the same topics talked about in this article? I’d really like to be a part of online community where I can get responses from other knowledgeable people that share the same interest. If you have any suggestions, please let me know. Appreciate it!|

  10. Simply want to say your article is as surprising. The clarity in your post is just excellent and i can assume you are an expert on this subject. Well with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please carry on the gratifying work.|

  11. great put up, very informative. I’m wondering why the opposite experts of this sector don’t realize this. You must proceed your writing. I’m confident, you have a great readers’ base already!|

  12. I absolutely love your blog.. Great colors & theme. Did you build this web site yourself? Please reply back as I’m trying to create my own personal website and would like to find out where you got this from or exactly what the theme is named. Thank you!|

  13. Oh my goodness! Incredible article dude! Thank you so much, However I am encountering troubles with your RSS. I don’t know why I cannot subscribe to it. Is there anybody else getting identical RSS problems? Anybody who knows the answer can you kindly respond? Thanks!!|

  14. First of all I would like to say fantastic blog! I had a quick question which I’d like to ask if you do not mind. I was interested to know how you center yourself and clear your mind prior to writing. I have had a hard time clearing my thoughts in getting my thoughts out. I truly do enjoy writing but it just seems like the first 10 to 15 minutes are generally lost simply just trying to figure out how to begin. Any suggestions or hints? Appreciate it!|

  15. It’s a shame you don’t have a donate button! I’d most certainly donate to this brilliant blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to brand new updates and will share this website with my Facebook group. Talk soon!|

  16. I used to be suggested this blog through my cousin. I am now not sure whether or not this publish is written via him as no one else understand such certain about my problem. You’re incredible! Thank you!|

  17. Very good site you have here but I was curious if you knew of any user discussion forums that cover the same topics discussed here? I’d really love to be a part of community where I can get responses from other knowledgeable people that share the same interest. If you have any recommendations, please let me know. Thanks a lot!|

  18. Hi there just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading correctly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same outcome.|

  19. Hello would you mind stating which blog platform you’re working with? I’m looking to start my own blog in the near future but I’m having a difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S Sorry for being off-topic but I had to ask!|

  20. I was wondering if you ever thought of changing the structure of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or 2 images. Maybe you could space it out better?|

  21. I absolutely love your blog and find most of your post’s to be just what I’m looking for. Does one offer guest writers to write content for you? I wouldn’t mind producing a post or elaborating on some of the subjects you write with regards to here. Again, awesome web log!|

  22. First of all I would like to say fantastic blog! I had a quick question in which I’d like to ask if you do not mind. I was curious to know how you center yourself and clear your thoughts prior to writing. I have had a hard time clearing my thoughts in getting my thoughts out. I do take pleasure in writing however it just seems like the first 10 to 15 minutes are generally lost just trying to figure out how to begin. Any suggestions or hints? Many thanks!|

  23. I’ve been surfing on-line more than 3 hours nowadays, but I by no means found any fascinating article like yours. It’s beautiful value sufficient for me. In my opinion, if all web owners and bloggers made excellent content material as you did, the net might be a lot more helpful than ever before.|

  24. Hey just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different web browsers and both show the same outcome.|

  25. Hey there! Someone in my Myspace group shared this site with us so I came to take a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers! Fantastic blog and outstanding design and style.|

  26. Hey this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get advice from someone with experience. Any help would be enormously appreciated!|

  27. Greetings from Idaho! I’m bored to tears at work so I decided to check out your website on my iphone during lunch break. I really like the info you provide here and can’t wait to take a look when I get home. I’m amazed at how quick your blog loaded on my cell phone .. I’m not even using WIFI, just 3G .. Anyways, fantastic blog!|

  28. wonderful put up, very informative. I wonder why the opposite experts of this sector do not realize this. You should proceed your writing. I’m sure, you’ve a huge readers’ base already!|

  29. Heya! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no backup. Do you have any solutions to stop hackers?|

  30. Hi there, I do believe your blog could possibly be having browser compatibility issues. When I take a look at your blog in Safari, it looks fine but when opening in IE, it has some overlapping issues. I just wanted to provide you with a quick heads up! Besides that, excellent site!|

  31. Great items from you, man. I’ve bear in mind your stuff previous to and you are simply extremely fantastic. I actually like what you’ve received here, certainly like what you are saying and the best way wherein you are saying it. You’re making it entertaining and you still take care of to stay it smart. I can not wait to learn far more from you. That is really a wonderful website.|

  32. Oh my goodness! Amazing article dude! Thanks, However I am going through problems with your RSS. I don’t know why I can’t join it. Is there anybody having identical RSS issues? Anyone that knows the answer will you kindly respond? Thanx!!|

  33. I’m truly enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Excellent work!|

  34. Hi this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding know-how so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!|

  35. Hi there would you mind letting me know which hosting company you’re utilizing? I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot quicker then most. Can you suggest a good internet hosting provider at a honest price? Many thanks, I appreciate it!|

  36. Hello, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you reduce it, any plugin or anything you can advise? I get so much lately it’s driving me mad so any help is very much appreciated.|

  37. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You obviously know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something informative to read?|

  38. You could certainly see your skills within the article you write. The world hopes for more passionate writers such as you who are not afraid to say how they believe. Always follow your heart.|

  39. Thanks for every other excellent post. Where else may anyone get that type of information in such a perfect means of writing? I’ve a presentation next week, and I am on the search for such info.|

  40. Hmm is anyone else encountering problems with the pictures on this blog loading? I’m trying to figure out if its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.|

  41. I’ll right away take hold of your rss as I can not find your e-mail subscription hyperlink or newsletter service. Do you have any? Please allow me realize so that I could subscribe. Thanks.|

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/03/24/php-training-institutes-gurgaon
YouTube49
YouTube