Posted by gosha bine on 05/13/07 11:51
Jon Slaughter wrote:
> 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 have the following function in my 'standard library'
function ary($a = NULL) {
return is_null($a) ? array() : (is_array($a) ? $a : func_get_args());
}
using this, your 'Decrypt' and other 'polymorphic' functions can be
simplified to
function polyfunc($arg) {
foreach(ary($arg) as $val)
.....
}
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Navigation:
[Reply to this message]
|