Switch Statement in PHP

php switch statement

Switch statement is conditional statement. It is used same as if else if statement. It is used to find the best condition. Its simple code is given bellow


 <?php  
                          $name="Feroz"; //Need to asign a value to variable  
                switch ($name) //need to add variable which needs to optimise for condition  
                               {  
                                    case "Sami":   
                                    echo "I am Sami";  
                                    break;  
                                    case "ullah":  
                                    echo "I am Samee Ullah";  
                                    break;  
                                    case "sheikh":  
                                    echo "I am Sheikh";  
                                    break;  
                                    case "Feroz":  
                                    echo "I am Samee Ullah Feroz";  
                                    break;  
                                    default:  
                                    echo "I m Samee Ullah Feroz cast sheikh";  
                               }  
                          ?>  

Updated 22 Oct, 2013:
Some times, we forget to add break after completion of any case. It can create bug in your output. Because in this situation, code will execute other cases and also will show their outputs.

Post a Comment

Give your reviews about this blog. Leave your comments. What do you think about this post?

Comments Guidelines:

1) I love to read comments, but please avoid spam.

2) Like this blog, share your insights, and spread the word.

3) You can use basic HTML/xHTML tags.

4) All comments are DoFollow—please use the section professionally.

5) Kindly mention your name or brand below your comment.

6) Constructive suggestions for improvement are always welcome.


Thanks for visiting Samee Articles.

========================================

Best Regards,

Samee U. Feroz

 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger