RE: [PHP] Setting counter in variable name within foreach loop

From: Date: Mon, 24 Nov 2003 03:59:51 +0000
Subject: RE: [PHP] Setting counter in variable name within foreach loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-170764@lists.php.net to get a copy of this message
>> $date_$counter = $value[1]; <-- this is line 33 >> $dest_$counter = $value[3]; >> $dep_$counter = $value[4]; you can't do that you'd have to do something like $mydate[$counter] = $value[1]; _________________ Nigel Jones njonez@ihug.co.nz >> -----Original Message----- >> From: Jake McHenry [mailto:linux@nittanytravel.com] >> Sent: Monday, November 24, 2003 4:55 PM >> To: php-general@lists.php.net >> Subject: [PHP] Setting counter in variable name within foreach loop >> >> >> 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 >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>

« previous php.general (#170764) next »