How can a configuration file be structured to allow for easy access and modification of settings in a PHP web application?

To allow for easy access and modification of settings in a PHP web application, a configuration file can be structured using an associative array. Each setting can be defined as a key-value pair within the array, making it easy to access and modify specific settings. This approach also allows for grouping related settings together, making the configuration file more organized and easier to manage.

// config.php

$config = [
    'database' => [
        'host' => 'localhost',
        'username' => 'root',
        'password' => 'password',
        'dbname' => 'my_database'
    ],
    'debug' => true,
    'timezone' => 'UTC'
];

// Accessing a setting
echo $config['database']['host']; // Output: localhost

// Modifying a setting
$config['debug'] = false;