Fetch Keywords from comment and assign keyword id to comment
From performance point of view, 40 iterations is nothing.

However, given such a condition that your keywords are like the Highlanders, as there could be only one, the number of repetitions could be reduced as we won't need anymore after we get one.

foreach($matches as $match) {   //only 1
    foreach ($match as $item) {    //max 10 if a user is mad :\
        foreach ($keywords as $keyword) {   //Max 4
            $keywordBody = strtolower($keyword['keyword_name']);
            if ($item === $keywordBody) {
                    $comment['keyword_id'] = $keyword['id'];
                    break 3; // stop all loops
                }
            }
        }
    }
}