Implement the "merge" filter from PHP Twig

This isn't as trivial a piece of functionality as it is in PHP, where values are
merged using the built-in array_merge function. This implementation has been
made with PHP compatibility in mind, mirroring the behaviour of PHP's
array_merge to the extent possible.