In the following code I've used if statement
<?php
$country="";
if ($country=="Pakistan")
echo "Hi, You have selected Pakistan";
elseif ($country=="India")
echo "Hi, You have selected India";
elseif ($country=="United states")
echo "Hi you have selected US";
else
echo "Your country is not in our list";
?>
Now in the following code i've used PHP switch () function to accomplish the same task as by if statement
<?php
$country="";
switch ($country)
{
case "Pakistan";
echo "Hi, You have selected Pakistan";
break;
case "India":
echo "Hi, You have selected India";
break;
case "United states":
echo "Hi you have selected US";
break;
default:
echo "Your country is not in our list";
}
?>
If we add Pakistan, India or united state in $country variables in both of the codes and execute them the result would be same in case of both if statement and switch ().
So actually what is difference between switch() and if statement.