Is it advisable to create separate PHP files for each API key in a configuration file, or is there a more efficient way to handle API key rotation?

It is advisable to store API keys in a configuration file for easier management and rotation. However, creating separate PHP files for each API key can become cumbersome to maintain. A more efficient way to handle API key rotation is to store all API keys in a single configuration file and retrieve them as needed.

// config.php
$apiKeys = [
    'api_key_1' => 'your_api_key_1',
    'api_key_2' => 'your_api_key_2',
    'api_key_3' => 'your_api_key_3',
];

// To retrieve API key
function getApiKey($key) {
    global $apiKeys;
    
    if (array_key_exists($key, $apiKeys)) {
        return $apiKeys[$key];
    } else {
        return null;
    }
}

// Example of retrieving API key
$apiKey = getApiKey('api_key_1');