Compare $_POST returned values with term array

Just check if $_POST contains key with id of correstponding term.

if (isset($_POST['recvid'][$term->term_id])) {

However, I would not loop through all the terms. get_terms function has corresponding option. So, to receive all posted ids, you would do this (also note, that first parameter may be a string, no need for an array):

$brands = get_terms('recipebrands', [ 
    'include' => array_filter(array_keys($_POST['recvid']), function($value) { return is_numeric($value); }),
]);

What above code does?

  • array_keys returns $_POST array keys obviously.
  • array_filter filters out only numeric keys (see anonymous function).
  • include option of get_brands() allows you to specify exact ids of terms you require.