Page 1 of 1

dynamic strings in foreach routine

Posted: Wed Mar 09, 2011 1:40 pm
by pedroz
How can I have the following in a foreach routine?

$feed1 = new SimplePie();
$feed1->set_feed_url($url->feed_url);
feed1->init();

$feed2 = new SimplePie();
$feed2->set_feed_url($url->feed_url);
feed2->init();

Code: Select all

$count = 0;
foreach ($feedz as $url) {
$feed$i = new SimplePie();
$feed$i->set_feed_url($url->feed_url);
$feed$i->init();
$count++;
}
I know it does not work, the reason I asked your help

tried with $feed[$i] but it gets some strange values from the class. works perfect if it is $feed1, $feed2, ... but gives me problems if it is $feed[1], $feed[2]

Re: dynamic strings in foreach routine

Posted: Wed Mar 09, 2011 1:59 pm
by AbraCadaver
You'll have to be more specific about the problems. $feed[$i] would be the way to go here. BTW. You are using $i but incrementing $count. They should be the same: $i++;