What are some best practices for storing variables in external files in PHP for easy access and modification?

Storing variables in external files in PHP is a common practice to separate configuration settings or constants from the main codebase for easier access and modification. One best practice is to use PHP files with defined constants or arrays to store variables, making it easy to include and access them in your scripts.

// config.php
<?php

define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', 'password');
define('DB_NAME', 'database_name');

// index.php
<?php

include 'config.php';

echo DB_HOST; // Output: localhost
echo DB_USER; // Output: root
echo DB_PASS; // Output: password
echo DB_NAME; // Output: database_name