filters – Why anything done on comments_array hook gets reset?


I am writing a plugin that will allow simple comment upvoting.

I am trying to sort comments by the number of upvotes. But anything I do on the comments_array Hook gets somehow reset. My question is where and how?

Here is my code:

add_filter( 'comments_array', 'biiird_order_comments_by_likes' );
function biiird_order_comments_by_likes( $array ) {

    $arraya = $array;

    usort($arraya, function($a, $b) {
        $likes_a = get_comment_meta( $a->comment_ID, 'likes', true );
        $likes_b = get_comment_meta( $b->comment_ID, 'likes', true );
        
        return ($likes_a > $likes_b) ? -1 : 1;

    });

    foreach ( $arraya as $comment ) {
        $comment->comment_content .= 'something';
    }
    var_dump($arraya);
    var_dump($array);

    return $arraya;
}

The var_dump($arraya) outputs a modified array in the proper order, but the comments show on a page as if the filter was not run.