Setting counter in variable name within foreach loop
From: Jake McHenry (linux_at_nittanytravel.com)
Date: 11/24/03
- Next message: John Nichel: "Re: [PHP] when to use \n in forms"
- Previous message: Nigel Jones: "RE: [PHP] when to use \n in forms"
- Next in thread: Nigel Jones: "RE: [PHP] Setting counter in variable name within foreach loop"
- Reply: Nigel Jones: "RE: [PHP] Setting counter in variable name within foreach loop"
- Reply: Curt Zirzow: "Re: [PHP] Setting counter in variable name within foreach loop"
- Reply: Pete M: "Re: Setting counter in variable name within foreach loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: John Nichel: "Re: [PHP] when to use \n in forms"
- Previous message: Nigel Jones: "RE: [PHP] when to use \n in forms"
- Next in thread: Nigel Jones: "RE: [PHP] Setting counter in variable name within foreach loop"
- Reply: Nigel Jones: "RE: [PHP] Setting counter in variable name within foreach loop"
- Reply: Curt Zirzow: "Re: [PHP] Setting counter in variable name within foreach loop"
- Reply: Pete M: "Re: Setting counter in variable name within foreach loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|