Setting counter in variable name within foreach loop

From: Jake McHenry (linux_at_nittanytravel.com)
Date: 11/24/03


To: <php-general@lists.php.net>
Date: Sun, 23 Nov 2003 22:54:40 -0500

Is this possible? I've been messing with this for about an hour now,
searching on google for about half hour. Here is what I want to do:

foreach ($array as $key => $value)
{
  $value = explode("|", $value);
  $counter = 0;

  if ($value[7] == "Yes")
  {
    $counter++;
    $date_$counter = $value[1]; <-- this is line 33
    $dest_$counter = $value[3];
    $dep_$counter = $value[4];
  }
}

Then later, I would like to do:

for ($i = 0; $i < $counter; $i++)
{
  echo "$date_$i, $dest_$i, $dep_$i<br>\n";
}

But, I get an error:
Parse error: parse error, unexpected T_VARIABLE in
/var/www/secure/travelrequest/travel7.php on line 33

Is there a way I can do this?

Thanks,

Jake McHenry
Nittany Travel MIS Coordinator
http://www.nittanytravel.com



Relevant Pages

  • Re: Substr Error
    ... > I've be messing with this for some time now, I'm trying to read a field ... For some reason my line that contains the susbtr ... > everytime no matter what. ... I get a Parse error: ...
    (php.general)
  • Substr Error
    ... I've be messing with this for some time now, I'm trying to read a field ... For some reason my line that contains the susbtr ... everytime no matter what. ... I get a Parse error: ...
    (php.general)
  • Add/ Remove fails to work PLEASE HELP! Emergency
    ... >>That would kinda be my last resort, lol at the mo i ... >really want to know what this parse error is and why its ... >messing up my computer. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: explain this.....
    ... When I try this in my compiler it outputs: ... error: parse error before "for" ... If you're posting through Google read ...
    (comp.lang.c)