I wrote a recurring function to apply a user function on every non-array member of given unknown depth array
<p>please tell me how I can improve this code:</p>

<pre><code>&lt;?php
class TEST {
 function awalkstr($func,$a) {
  $args = func_get_args(); array_shift($args);array_shift($args);
  foreach ($a as &amp;$val) {
   if (!is_array($val)) $val = call_user_func_array($func,array_merge(array($val),$args));
   else $val = call_user_func_array(__METHOD__,array_merge(array($func),array($val),$args));
  }
  $a = array_filter($a,function ($v) {return isset($v);});
  return($a);
 }
 function upper_reverse_add($str,$add) {
  return (strlen($str)==2) ? null : $add.strtoupper(strrev($str));
 }
}

$test = new TEST();
$testarr = array(
    'uk'=&gt;'london',
    array(
        'us'=&gt;'ny',
        array(
            'california'=&gt;'la',
            array(
                'tokyo',
                array('paris'),
                'rome'
            ),
            'moscow'
        ),
        'dublin',
        array(
            'berlin',
            array('warsaw')
        )
    ),
    'madrid',
    'lapaz'
);
print_r($test-&gt;awalkstr(array($test,'upper_reverse_add'),$testarr,'teststr-'));
?&gt;
</code></pre>

<blockquote>
<pre><code>Array (
[uk] =&gt; teststr-NODNOL
[0] =&gt; Array
    (
        [0] =&gt; Array
            (
                [0] =&gt; Array
                    (
                        [0] =&gt; teststr-OYKOT
                        [1] =&gt; Array
                            (
                                [0] =&gt; teststr-SIRAP
                            )

                        [2] =&gt; teststr-EMOR
                    )

                [1] =&gt; teststr-WOCSOM
            )

        [1] =&gt; teststr-NILBUD
        [2] =&gt; Array
            (
                [0] =&gt; teststr-NILREB
                [1] =&gt; Array
                    (
                        [0] =&gt; teststr-WASRAW
                    )

            )

    )

[1] =&gt; teststr-DIRDAM
[2] =&gt; teststr-ZAPAL )
</code></pre>
</blockquote>
