Big LOL and thanks @Bob...I really tried to find what's wrong, but didn't, I even didn't see it when you posted the correct code, had to move both code pieces into my editor to have a look at it and see, if I would have done it there (instead of the forum textarea) I would have seen it, probably =D, sometimes just blind...look here:
if ( $tvval === $query ) ) {
and here
return implode(',' $resources);
just one little closing parenthesis too much, a comma missing...equals parse error =D...man...learn: don't write code out of your head in a plain textarea^^