Foreach loop with the array of a public function

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
mofle
Forum Newbie
Posts: 6
Joined: Fri Apr 06, 2007 10:02 pm

Foreach loop with the array of a public function

Post by mofle »

Hi, i need to do a loop of the array of this function found in the WebUI API:

Code: Select all

public function getTorrents()

WebUI API: http://pastebin.com/m76205d0b


I have this one, but it doesn't work.

Code: Select all

$utorrent = new uTorrent();
$utorrent->host = $_SESSION['host'];
$utorrent->user = $_SESSION["user"];
$utorrent->pass = $_SESSION["pass"];
$torrents = $utorrent->getTorrents();
 
foreach($torrents as $torrent) {
    echo $torrent[UTORRENT_TORRENT_NAME]."\n";
}
How do i use the "public function getTorrents()" to get the array into a foreach loop?

I really appreciate your help ;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Foreach loop with the array of a public function

Post by RobertGonzalez »

Try looking at the return of that method using var_dump(). See what is coming from it.
mofle
Forum Newbie
Posts: 6
Joined: Fri Apr 06, 2007 10:02 pm

Re: Foreach loop with the array of a public function

Post by mofle »

I've tried using the var_dump(), the result was:
NULL Array
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Foreach loop with the array of a public function

Post by RobertGonzalez »

There is something that is not being set properly. You may need to inspect each variable for each step of the code.
Post Reply