On 4/18/07, Yvan Strahm <[EMAIL PROTECTED]> 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

Reply via email to