How can the switch statement be used to handle multiple domains in PHP?
When dealing with multiple domains in PHP, a switch statement can be used to easily handle different cases based on the domain name. By extracting the domain from the URL and using a switch statement to check against different cases, you can execute specific code based on the domain.
// Get the current domain from the URL
$domain = $_SERVER['HTTP_HOST'];
// Use a switch statement to handle different domains
switch ($domain) {
case 'example.com':
// Code to execute for example.com
break;
case 'anotherdomain.com':
// Code to execute for anotherdomain.com
break;
default:
// Default code to execute if domain doesn't match any case
break;
}