automatic generate variable names in PHP

I ran into the Problem that I had to write a PHP program that generates individual variable names for objects (a script to create an ics file).
I’m getting the events from the Database and then I use a for loop to create the object for each event.

the PHP code

//get data from DB
for($i = 0; $i < $count_events; $i++){
${vevent.$i} = & $v->newComponent( "vevent" );
${vevent.$i}->setProperty( "dtstart", $start);
${vevent.$i}->setProperty( "dtend", $end);

${vevent.$i} creates a new name every time the program runs trough the for loop, adding the counter to the variable name.

I used this code for a calendar project I was working on. I needed to generate individual variable names in a for loop to creat an [[ics]] file. The events are stored in a MySQL Database. I’m using this little Script to generate the ics file. This file can be imported into Google Calendar or any other Calendar Program.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s