Hi Gaia,
There’s no special requirements when creating functions etc., you can just create them as you would in normal PHP code.
You can either include the function within your snippet/module code or separate it out into an include file. It all depends on your application - if it’s a function that will be utilised in more than one snippet/module, then I would recommend going down the include file route.
If you do create a separate include file, then a tip is to prefix it with the basepath of your install - makes the code more portable across different setups:
$basePath = $modx->config['base_path'];
include_once $basePath . 'assets/snippets/mysnippet/functions.inc.php';
Where you create the files is entirely up to you, but I would recommend that you try and maintain the structure defined in the ’assets’ directory to make life easier in terms of future MODx upgrades.
Hope that helps, Garry