What are the advantages of using an index.php file as the entry point for an application and how can it be utilized effectively in PHP scripts for navigation purposes?

By using an index.php file as the entry point for an application, you can have a centralized location for routing and handling incoming requests. This can help organize your code structure and make it easier to manage navigation within your application. Additionally, using an index.php file allows you to easily implement URL rewriting and clean URLs for better SEO and user experience.

<?php
// index.php

// Include necessary files and define routes
require 'router.php';

// Get the requested URL
$request_uri = $_SERVER['REQUEST_URI'];

// Route the request to the appropriate controller based on the URL
switch ($request_uri) {
    case '/':
        include 'home.php';
        break;
    case '/about':
        include 'about.php';
        break;
    case '/contact':
        include 'contact.php';
        break;
    default:
        include '404.php';
        break;
}
?>