How to filter part of a variable if it is no array?

The documentation is well explicable of the topic, let’s have a look here https://developer.wordpress.org/reference/functions/apply_filters/.

In your specific case my_filter is applied no matter what, even if there is no value it. To apply the filter only if is_array() you could insert a specific instruction directly into your filter like:

function example_callback( $output ) {
    if(is_array($output)){
        //do something and replace part of the string with str_replace()
    }
    return $output;
}
add_filter( 'my_filter', 'example_callback', 10, 1 );

About the str_replace() php function read more here http://php.net/manual/en/function.str-replace.php.

tech