Posted by Jon Slaughter on 05/14/07 03:55
"gosha bine" <stereofrog@gmail.com> wrote in message
news:4646fd34$0$2892$6e1ede2f@read.cnntp.org...
> 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)
> .....
>
> }
Cool that will work just fine.
Thanks, Jon
[Back to original message]
|