Setting counter in variable name within foreach loop
| From: | Jake McHenry | Date: | Mon, 24 Nov 2003 03:54:40 +0000 |
| Subject: | Setting counter in variable name within foreach loop | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-170761@lists.php.net to get a copy of this message | ||
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