<?php
/**
* Deduplicates environment variables. For development use only.
* Synchronous execution.
*/
/**
* Deduplicates environment variables.
* @param array $env An array of environment variables (key => value).
* @return array A new array with deduplicated environment variables.
*/
function deduplicateEnv(array $env): array
{
$uniqueEnv = [];
$seenValues = [];
foreach ($env as $key => $value) {
// Check if the value has already been seen.
if (!in_array($value, $seenValues)) {
$uniqueEnv[$key] = $value;
$seenValues[] = $value;
}
}
return $uniqueEnv;
}
// Example Usage (replace with your actual environment variables)
$environmentVariables = [
'DEBUG' => 'true',
'LOG_LEVEL' => 'INFO',
'DATABASE_URL' => 'mysql://user:password@host:port/db',
'DEBUG' => 'false', // Duplicate
'LOG_LEVEL' => 'WARNING', // Duplicate
'API_KEY' => 'abcdef123456',
'DATABASE_URL' => 'mysql://user:password@host:port/db' // Duplicate
];
$deduplicatedVariables = deduplicateEnv($environmentVariables);
// Print the deduplicated environment variables
print_r($deduplicatedVariables);
?>
Add your comment