How can PHP functions be utilized to streamline the retrieval of specific attributes from a multidimensional array in a website configuration?

When dealing with a multidimensional array in a website configuration, it can be cumbersome to retrieve specific attributes manually. PHP functions can be utilized to streamline this process by creating a function that accepts the array and a key as parameters, and returns the value associated with that key. This way, you can easily access specific attributes without having to navigate through the array structure each time.

function getAttributeValue($config, $key) {
    $keys = explode('.', $key);
    $value = $config;

    foreach ($keys as $k) {
        if (isset($value[$k])) {
            $value = $value[$k];
        } else {
            return null;
        }
    }

    return $value;
}

// Example usage
$config = [
    'website' => [
        'name' => 'My Website',
        'url' => 'https://www.example.com',
        'settings' => [
            'theme' => 'light',
            'logo' => 'logo.png'
        ]
    ]
];

$websiteName = getAttributeValue($config, 'website.name');
echo $websiteName; // Output: My Website

$logo = getAttributeValue($config, 'website.settings.logo');
echo $logo; // Output: logo.png