You are here: array and value type « PHP Programming Language « IT news, forums, messages
array and value type

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация