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

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]


Удаленная работа для программистов  •  Как заработать на 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

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