Problems with printing values in foreach.

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
lase
Forum Newbie
Posts: 5
Joined: Thu May 07, 2009 10:05 am

Problems with printing values in foreach.

Post by lase »

So I'm working on a script and having immense difficulties using foreach. I've been trying solutions in the manual but to no avail.

Here's the code I'm using and having trouble with:

Code: Select all

foreach ($this->matches as $page) {
            print "$page";
            echo "<br />";
}
$this->matches refers to a preg_match_all instance. The problem is, is that whenever I print the value, it says "Array" on the page, instead of the value like it should. Getting rather frustrated and wondering if it's a problem deeper than my coding :P
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Problems with printing values in foreach.

Post by papa »

$this->matches is probably a multi-dimensional array so you need to go deeper in your loop.

Do a print_r($this->matches) and see how it looks.
lase
Forum Newbie
Posts: 5
Joined: Thu May 07, 2009 10:05 am

Re: Problems with printing values in foreach.

Post by lase »

papa wrote:$this->matches is probably a multi-dimensional array so you need to go deeper in your loop.

Do a print_r($this->matches) and see how it looks.
Ahh, that seemed to fix it. Added another foreach loop inside my current foreach loop and it works now. :D

Thanks.
Post Reply