Create a service and include your common functions in it. For example, you can name it ArrayService and register it in the container as array.service . Then you can access this service from the controllers through
$this->get('array.service');
and from teams through
$this->getContainer()->get('array.service');
So your code will look something like this:
$element = $this->get('array.service')->last($array); // or ->arrayLast($array)
If you need the same functionality in several projects, create a package with this service and add it to the deps file of each project. It will then be installed when running bin/vendors install script.
source share