dynamic strings in foreach routine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

dynamic strings in foreach routine

Post 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]
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: dynamic strings in foreach routine

Post 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++;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply