Download as pdf
Download as pdf
You are on page 1of 17
r mie MSO : WordPress Magento 2 selenite YT ML CSS —_IavaSerp oe innjerpaetcomprptin cot PHP Switch PHP switch statement is used to execute one statement from multiple conditions. It works lke PHP if-else-if statement. Syntax ‘switch(expression)¢ case valuet Heode to be executed break ‘case value2: Hcode to be executed break default code to be executed if all cases are not matched: ) Important points to be noticed about switch case: 1. The default is an optional statement. Even it is not important, that default must always be the last statement. oe innjerpaetcomprptin 2 There can be only one default in a switch statement, More than one default may lead toa Fatal error. Each case can have a break statement, which is used to terminate the sequence of statement. The break statement is optional to use in switch. If break is not used, all the statements will execute after finding matched case value, PHP allows you to use number, character, string, as well as functions in switch expression Nesting of switch statements is allowed, but it makes the program more complex and less readable. You can use semicolon () instead of colon (). It will not generate any ertor. soem egorecamrp anton PHP Switch Flowchart Pu Secret PHP Switch Example "; case’: echo "Choice d's ‘echo *
"; default echo “ease a,b, ¢, and d isnot found’; Output: choice ¢ choice 6 case a, b, ¢, and d is not foune PHP nested switch statement Nested switch statement means switch statement inside another switch statement ‘Sometimes it leads to confusion <2php. Sear "Hyundai"; oe innjerpartcomprptin Smodel = "Tucson"; switch $ear) ‘ cease “Honda” switch $mode! ‘ case “Amaze echo "Honda Amaze price is 593 - 9.79 Lakh break: iy’ echo "Honda City price is 991 - 1431 Lakh”; break: > break: cease "Renault switch $model ‘ cease "Duster echo “Renault Duster price is 9.15 - 1483 L break: case "kui echo "Renault Kwid price is 315-544 L*: break: oe innjerpartcomprptin break; cease "Hyundai" switch $model ) ‘ ease "Greta" echo "Hyundai Creta price is 11.42 - 18.73 L"; break: echo "Hyundai Tueson price is 22.39 - 32.07 L"; break; (cent echo "Hyundai Xeent price is 65 - 10.05 L"; break: > break; » Output: Hyundai Tucson price is 22.39 - 32.07 L. oe innjerpaetcomprptin 7) © For Videos Join Our Youtube Channel: Join Now Feedback © Send your Feedback to feedback/@javatpoint.com Help Others, Please Share Leam Latest Tutorials ® selon soe Splunk sess Swagger oe innjerparecomprptin “rama SQL. Regex Regex PRUS worl Rus | Python Pillow ‘torial Python Pillow Preparation Baptiude Aide Bi Amerview Questions oe innjerparecomprptin Reinforcement ‘Leaning 1B React Native tutorial React Native #2 Python Turtle ‘torial Python Tune D Logical Reasoning Reasoning R Programming 122 Python Design Patterns Python Desien Pacers PXeras tutorial Kes Yerba Ability Verbal Abiity Intriew Quesiont B Company Interview eestons Company Questions Trending Technologies 2 Awificial AWS Turia Iateligence vs Aci snigene 2 Cloud Hadoop tral ‘Compating Hadoop oud Concing 2 DataScience —g)_Angular? Tutsi Tutorial ‘eae? AG Tworal —Z_ Machine ce Teaming Tuoi Machine Leaning oe innjerparecomprptin Selenium torial Seleniam ReactlS Tutorial Rescls Blockohsi Tutorial Blockshsin DevOps ‘Tutorial DevOps B.Tech | MCA ADAMS torial poms BD Operating System peating Sytone A. Computer Onganization and “Architecture Computer Owanizasion 2 Computer “Graphics Tutorial Computer Graphice oe innjerpaetcomprptin AData Structures oral Data States 2 Computer ‘Netware utrial Computer Neswork A__ Discrete Mathematics Tutorial Discrete Mathematics B_ Software Enginesring Software Engineering PAA tuorial DAA A Compiler Design tutorial Compile Design AEAhieal Hacking hcl Hacking (Pitan tutorial ‘Web Technology PiCyber Security ‘tora Cyber Security aC tutorial cH PP ython torial Python 2 Data Mining Tutorial ata Mining oe innjerpaetcomprptin Bi Automata Tutorial Automata (aiJava tutorial Java DB _ Listot Programs Programs 2B Dae ‘Warehouse Tutorial ata Warehouse BC Language ‘wional (© Programmi 2 Ne Framework Tutorial Net BR Contot ‘Systems tutrial Cont System

You might also like