How can the function getRights be modified to return the desired value instead of an array?

The issue can be solved by modifying the getRights function to return the desired value directly instead of returning an array. This can be done by accessing the specific value within the array and returning it. By making this change, the function will directly return the desired value without needing to access it from the array.

function getRights($user) {
    $rights = [
        'admin' => 1,
        'editor' => 2,
        'viewer' => 3
    ];
    
    if (isset($rights[$user])) {
        return $rights[$user];
    }
    
    return null;
}

// Example usage
$user = 'admin';
$rights = getRights($user);
echo $rights; // Output: 1