Page 1 of 1

Problems with printing values in foreach.

Posted: Thu May 07, 2009 10:10 am
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

Re: Problems with printing values in foreach.

Posted: Thu May 07, 2009 10:21 am
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.

Re: Problems with printing values in foreach.

Posted: Thu May 07, 2009 10:26 am
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.