Array is not working in Filter?

You cannot define something outside a function and then simply try to use it inside the function without calling it into the function. This is basic PHP and how functions work in general.

You need to pass that specific something to the function or define that something inside the function or use a method to globalize that something and then invoking it inside the function

On the topic of “globalizing”, never ever use global variables to globalise a value. WordPress has already made such a big mess of it. Globals are evil, period. If you need to globalize something, use a function. For example

funtion get_global_array()
{
    // Return an array with values 1, 2 and 3
    return [1, 2, 3];
}

You can now use get_global_array() anywhere where needed like inside of another function or filter function