Please explain what happens when PHP switch case executes case 0?



The PHP is a loosely typed language. When you match with case 0 the string matches with closest integer.

Let’s say we have the following switch expression −

switch ("match")

Now, we will match with case 0 −

case 0:     echo " 0 with match";     break;

We will also match for non-zero case −

case "match":     echo "match successful";     break;

Example

 Live Demo

<!DOCTYPE html> <html> <body> <?php switch ("match") {    case 0:        echo " 0 with match";        break;    case "match":        echo "match successful";        break;    } ?> </body> </html>

Output

0 with match
Updated on: 2020-10-12T12:57:59+05:30

197 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements