<?php
/**
* Maps configuration values from a temporary configuration array.
*
* @param array $config_values An array of configuration values. Keys are the field names.
* @param array $field_mapping An array mapping field names to their desired values.
* @return array An array of configured values, using the provided field mapping.
*/
function mapConfiguration(array $config_values, array $field_mapping): array
{
$configured_values = [];
foreach ($config_values as $field => $value) {
// Check if the field has a mapping
if (isset($field_mapping[$field])) {
$configured_values[$field] = $field_mapping[$field];
} else {
// Use the original value if no mapping is defined.
$configured_values[$field] = $value;
}
}
return $configured_values;
}
// Example Usage:
// $config = ['database_host' => 'localhost', 'debug_mode' => 'false', 'api_key' => ''];
// $mapping = ['database_host' => 'remote_host', 'debug_mode' => 'true'];
// $configured_config = mapConfiguration($config, $mapping);
// print_r($configured_config);
?>
Add your comment