Code to join filesystem path strings in PHP Following code has some issues:

$args = func_get_args();
$paths = array();
foreach ($args as $arg) {
    $paths = array_merge($paths, (array)$arg);
}

$paths = array_map(create_function('$p', 'return trim($p, DIRECTORY_SEPARATOR);'), $paths);
$paths = array_filter($paths);
return DIRECTORY_SEPARATOR . join(DIRECTORY_SEPARATOR, $paths);



Unnecessary array_merge usage
Using depecated create_function function


Would using modern PHP 5.6+ features (anonymous functions etc.. ) help to improve the code?
Seems like the problem has been over thought.  This would be how I would write it.

&lt;?php

//$args = func_get_args();
$args = array('foo/', '/bar', 'fiz');

$paths = [];

foreach ($args as $arg) {
    $paths[] = trim($arg, DIRECTORY_SEPARATOR);
}

$paths = array_filter($paths);

echo DIRECTORY_SEPARATOR . join(DIRECTORY_SEPARATOR, $paths);


I don't see any need to leverage any exclusive PHP 5.6+ features to solve this.