tags:

views:

32

answers:

1

please tell me how I can improve this code:

<?php
class TEST {
 function awalkstr($func,$a) {
  $args = func_get_args(); array_shift($args);array_shift($args);
  foreach ($a as &$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'=>'london',
    array(
        'us'=>'ny',
        array(
            'california'=>'la',
            array(
                'tokyo',
                array('paris'),
                'rome'
            ),
            'moscow'
        ),
        'dublin',
        array(
            'berlin',
            array('warsaw')
        )
    ),
    'madrid',
    'lapaz'
);
print_r($test->awalkstr(array($test,'upper_reverse_add'),$testarr,'teststr-'));
?>
Array (
[uk] => teststr-NODNOL
[0] => Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [0] => teststr-OYKOT
                        [1] => Array
                            (
                                [0] => teststr-SIRAP
                            )

                        [2] => teststr-EMOR
                    )

                [1] => teststr-WOCSOM
            )

        [1] => teststr-NILBUD
        [2] => Array
            (
                [0] => teststr-NILREB
                [1] => Array
                    (
                        [0] => teststr-WASRAW
                    )

            )

    )

[1] => teststr-DIRDAM
[2] => teststr-ZAPAL )
A: 

Use some better formatting for your code. The PEAR coding standards are a good place to start.

Inigoesdr