What are the best practices for accessing global attributes in PHP arrays?

When accessing global attributes in PHP arrays, it is important to use the 'global' keyword to access the global variable within a function. This allows you to modify the global variable directly within the function scope. Additionally, it is good practice to ensure that the global variable is initialized before accessing it to avoid any potential errors.

// Define a global variable
$globalArray = array('key1' => 'value1', 'key2' => 'value2');

// Access global variable within a function using the 'global' keyword
function accessGlobalArray() {
    global $globalArray;
    
    // Modify global variable
    $globalArray['key1'] = 'new value';
}

// Call the function to access and modify the global variable
accessGlobalArray();

// Print the updated global variable
print_r($globalArray);