name ); $category_info[] = strtolower( $category->slug ); $category_info[] = strtolower( $category->description ); } // Convert mobilizon categories to lowercase for case-insensitive comparison. $mobilizon_categories = array_map( 'strtolower', Event::DEFAULT_EVENT_CATEGORIES ); // Initialize variables to track the best match. $best_mobilizon_category_match = ''; $best_match_length = 0; // Check for the best match. foreach ( $mobilizon_categories as $mobilizon_category ) { foreach ( $category_info as $category ) { foreach ( explode( '_', $mobilizon_category ) as $mobilizon_category_slice ) { if ( stripos( $category, $mobilizon_category_slice ) !== false ) { // Check if the current match is longer than the previous best match. $current_match_legnth = strlen( $mobilizon_category_slice ); if ( $current_match_legnth > $best_match_length ) { $best_mobilizon_category_match = $mobilizon_category; $best_match_length = $current_match_legnth; } } } } } return ( '' != $best_mobilizon_category_match ) ? strtoupper( $best_mobilizon_category_match ) : 'MEETING'; } }