You are here: Re: Function returning 2 arrays - which way to do so? « PHP Programming Language « IT news, forums, messages
Re: Function returning 2 arrays - which way to do so?

Posted by C. (http://symcbean.blogspot.com/) on 01/07/08 12:20

On 7 Jan, 09:15, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote:
> jodleren wrote:
> > Hi!
>
> > I have a function, a part of my code which I can use as a function.
>
> I have no clue what that sentence means. :P
>
> It
>
> > will return 2 arrays, and I am wondering what way to do so. Both
> > arrays hold strings, there are no special keys.
<snip>
> I would go with something like 2, because it is the most structured
> approach in my opinion.
>
> Something like this:
>
> function gimme2(){
> $arr1 = array("hi","bla");
> $arr2 = array("more","of","this");
> $returnThis = array();
> $returnThis["arr1"] = $arr1;
> $returnThis["arr2"] = $arr2;
> return $returnThis;
>
> }
>
> // from code:
> $result = gimme2();
> // $result["arr1"] now contains first array, $result["arr2"] the second
<snip>
>
> I prefer returning complex datastructures as hashed arrays, because I
> can be more descriptive (like what holds what), but that is a matter of
> taste.

/me prefers not to explicitly create data structures which are only
used once:

function gimme2(){
$arr1 = array("hi","bla");
$arr2 = array("more","of","this");
return array($arr1, $arr2);
}

list($first, $second)=gime2();

C.

 

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

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