Replace only value is numeric or string

When value is a object or array, the php show error "Array to string conversion".