Function function_deep ($ function, $ value ){ Try { If (! Function_exists ($ function )){ $ Error = '"'. $ function. '" is undefined '; Throw new Exception ($ error ); } } Catch (Exception $ e ){ Echo 'caught exception: ', $ e-> getMessage (), "\ n "; Die (); } If (is_array ($ value )){ $ Fun = Array (); For ($ I = 1; $ I <= count ($ value); $ I ++ ){ $ Fun [] = $ function; } $ Value = array_map ("function_deep", $ fun, $ value ); } Elseif (is_object ($ value )){ $ Vars = get_object_vars ($ value ); Foreach ($ vars as $ key => $ data ){ $ Value-> {$ key} = function_deep ($ function, $ data ); } } Elseif (is_string ($ value )){ $ Value = call_user_func ($ function, $ value ); } Return $ value; } $ Arr = array ( "I'm bean ", "I'm bean ", Array ("I'm bean", "I'm bean ") ); Var_dump (function_deep ("addslashes", $ arr )); // Output result // Array (size = 3) // 0 => string 'I \'m Bean' (length = 9) // 1 => string 'I \'m Bean' (length = 9) // 2 => // Array (size = 2) // 0 => string 'I \'m Bean' (length = 9) // 1 => string 'I \'m Bean' (length = 9) ?> |