PHP SwitchPHP switch statement is used to execute one statement from multiple conditions. It works like PHP if-else-if statement. SyntaxImportant points to be noticed about switch case:
PHP Switch FlowchartPHP Switch ExampleOutput: number is equal to 20 PHP switch statement with characterProgram to check Vowel and consonant We will pass a character in switch expression to check whether it is vowel or constant. If the passed character is A, E, I, O, or U, it will be vowel otherwise consonant. Output: Given character is vowel PHP switch statement with StringPHP allows to pass string in switch expression. Let's see the below example of course duration by passing string in switch case statement. Output: B.Tech is 4 years course PHP switch statement is fall-throughPHP switch statement is fall-through. It means it will execute all statements after getting the first match, if break statement is not found. Output: Choice c Choice d case a, b, c, and d is not found PHP nested switch statementNested switch statement means switch statement inside another switch statement. Sometimes it leads to confusion. Output: Hyundai Tucson price is 22.39 - 32.07 L. Next TopicPHP For Loop |