500 Internal Server Error PHP 8.1 Array with wordpress

Problem solved (thx a lot to ChrisHaas)

replacing

 echo implode( $terms_array, '');

with

echo implode('', $terms_array); 

fixed it.

Historically the order of these parameters didn’t matter, however as of PHP 7.4 passing the array first was deprecated and it was completely removed in PHP 8.0.