| 
	
 | 
 Posted by Jon Slaughter on 05/12/07 19:54 
I want to create function that takes either an array or a simple type but I  
want it not to distinguish between them, 
 
 
function Decrypt(&$str) 
{ 
    foreach($str as &$val) 
    { 
        $val = rtrim($val,'enc'); 
    } 
    return $str; 
} // 
 
So here Decrypt can be called with an array or any type but the code should  
be the same 
 
i.e., I'd like to be able to call the function like Decrypt(1) or  
Decrypt('1234') and Decrypt(array('13', 4)) without having to modify the  
code. Essentially I need some polymorphic behavior but I'm not sure if php  
supports anything like this?  What I want is that in the above foreach loop  
that if str is not an array then val = str instead of it ignoring the loop  
completely. I know I can get around this by type comparision but I want to  
keep my decoding part(which is simply attaching enc here but is actually  
more complicated) in one spot... and I'd rather not create a seperate  
function if possible. 
 
My guess is that it won't be that easy though ;/ 
 
Thanks, 
Jon
 
  
Navigation:
[Reply to this message] 
 |