What are the potential pitfalls of using if-elseif statements instead of switch-case statements when handling different page requests in PHP?
Using if-elseif statements can lead to code duplication and make the code harder to read and maintain compared to switch-case statements. To solve this issue, you can use a switch-case statement to handle different page requests in a more concise and organized manner.
$page = $_GET['page'];
switch ($page) {
case 'home':
// code for home page
break;
case 'about':
// code for about page
break;
case 'contact':
// code for contact page
break;
default:
// code for default page
break;
}