Where to place php code snippets in Drupal?
You should place this helper function in your custom module, so once the module get enabled the you can call this function anywhere across drupal environment.