Parsed: 111297

function wp_create_categories( $categories, $post_id = '' ) {
  $cat_ids = array();
  foreach ( $categories as $category ) {
    $id = category_exists( $category );
    if ( $id ) {
      $cat_ids[] = $id;
    } else {
      $id = wp_create_category( $category );
      if ( $id ) {
        $cat_ids[] = $id;
      }
    }
  }

  if ( $post_id ) {
    wp_set_post_categories( $post_id, $cat_ids );
  }

  return $cat_ids;
}