View Single Post
Old 01-04-2006, 04:50 AM   PM User | #10
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road
Personally i prefer to redeclare the function if the existing function doesnt exist only once, as if you use the function alot there could be performance decrease for PHP5.

However, I have written a simple wrapper function here called "recursive_array_walk", which functions exactly the same as array_walk_recursive(). I also added in the same error checking and triggered errors as the real function:

PHP Code:
function recursive_array_walk( &$input$funcname$userdata NULL ){

    if( !
function_exists'array_walk_recursive' ) ){

        if( !
is_array$input ) ){

            
trigger_error'The argument should be an array'E_USER_WARNING );        
            return 
false;
        
        }

         foreach( 
$input as $key => $data ){
    
              if( 
is_array$data ) ){
    
                    if( 
false === recursive_array_walk$input[$key], $funcname$userdata ) ){
                    
                        return 
false;
                    
                    }
    
              } else {
    
                    if( 
is_array$funcname ) ){
    
                         
$obj $funcname[0];
                         
$method $funcname[1];
                         
                         if( 
method_exists$obj$method ) ){
                         
                             
$obj->$method$data$key$userdata );
                             
                         } else {
                         
                             
trigger_error'Unable to call ' get_class($obj) . "::$method() - function does not exist"E_USER_WARNING );
                             return 
false;
                            
                         }
                    
                    } else {
                    
                         if( 
function_exists$funcname ) ){
                         
                             
$funcname$data$key$userdata );
                         
                         } else {
                         
                              
trigger_error"Unable to call $funcname() - function does not exist"E_USER_WARNING );
                             return 
false;
                         
                         }
                         
                    }
              
              }
         
         }
         
    } else {
    
        return 
array_walk_recursive$input$funcname$userdata );
        
    }


missing-score is offline   Reply With Quote