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

PHPServer Side ProgrammingProgramming

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
raja
Published on 12-Oct-2020 12:56:48
Advertisements