Re: scope and return array( ); problems

From: Date: Wed, 18 Apr 2007 23:38:19 +0000
Subject: Re: scope and return array( ); problems
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-253221@lists.php.net to get a copy of this message
On 4/18/07, Yvan Strahm <yvan.strahm@gmail.com> wrote:
Hi all, I have this code ( but you already know it ;-) : function preg_array($pattern, $array, $r_array) {
    global $match;
    global $r_array;
    foreach ($array as $key => $value)
    {
      if (preg_match($pattern, $value,$match))
      {
        $r_array=array_slice($match,1);
        break;
      }
    }
return array ($r_array, $match); } $GA = array(); preg_array("/^GA\s+(\d+.\d+)\s+(\d+.\d+)/i", $PF, $GA) but the array $GA is empty outside the function, i tried to declare $GA also as global inside the function and it didn't change the output. It works if the function is change to this : function preg_array($pattern, $array, $GA) {
    global $match;
    global $GA;
    foreach ($array as $key => $value)
    {
      if (preg_match($pattern, $value,$match))
      {
        $GA=array_slice($match,1);
        break;
      }
    }
return array ($GA, $match); } What's wrong with the first version of the preg_array function? do I really need to have the same array name in order to retrieve the third argument of the function? Thanks for your help, yvan
sorry for the noise, a solution has been found : function preg_array($pattern, $array, &$r_array) cheers yvan

« previous php.general (#253221) next »