Using Switch Statement to Change Image According to Last Digit of Topic ID

I would try something like this:

function bg_image_topic_titlearea() {

    if ( ! function_exists( 'bbp_get_topic_id' ) ) {
        return false;
    }

    if ( ! $letztezifferimgs = bbp_get_topic_id() ) {
        return false;
    }

    $letztezifferimgs = substr( $letztezifferimgs, - 1 );

    // switch ...

    return true;

}

I would recommend checking to make sure the function call (bbp_get_topic_id();) to retrieve the Topic ID exists.

I would recommend checking to see if there’s actually a value received from the function call to retrieve the Topic ID.

Not sure why you need to use substr();, but perform that once you know you have received a Topic ID.

THEN perform your switch.

I would also recommend placing a “default case” in your switch statement.

Example of a “default case”:

default:

    // do something...

break;