Jump to content


Photo

[SOLVED] arrays/references - a quickie


  • Please log in to reply
2 replies to this topic

#1 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 11 October 2006 - 02:39 PM

Hi all
On PHP5 here - not sure if it makes a difference to the answer at all.

If a function/class method returns an array, is it best to pick it up by reference?

function myfunction()
{
   return $reallybigarray;
}

$thearray = myfunction();

or

function myfunction()
{
   return $reallybigarray;
}

$thearray = &myfunction();

cheers
Mark

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 11 October 2006 - 02:42 PM

I think references are always the way to go when passing around arrays, whether it's PHP, Perl, etc. Otherwise, the array has to be copied.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 11 October 2006 - 02:48 PM

ok cool, thanks!
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users