What role does IF statements play in customizing content based on URLs in PHP?

IF statements play a crucial role in customizing content based on URLs in PHP by allowing the code to check the current URL and execute specific actions or display certain content based on the conditions specified. By using IF statements, you can dynamically adjust the output of your PHP script based on the URL being accessed, providing a personalized experience for users.

$url = $_SERVER['REQUEST_URI'];

if ($url == '/page1') {
    echo "Content for Page 1";
} elseif ($url == '/page2') {
    echo "Content for Page 2";
} else {
    echo "Default Content";
}