CMB2 – array_search or in_array from repeat_group and comma separated values

$value['postal_codes'] is not an array it is a string, you either need to explode it like:

foreach ( $myoptions as $key => $value ) {
   if (in_array($p,explode(","$value['postal_codes']){
      // need to know $key of which array the $p was found, in this case I would like to find [0]
   }
}

Or search on the string

foreach ( $myoptions as $key => $value ) {
   if (strstr($value['postal_codes'],$p){

   }
}

Or the most efficient way would be use array_search on the exploded like so:

foreach($myoptions as $key => $options) {
   $keys_containing_p[$key] = array_search($p,explode(",",$options['postal_codes']));
}