Click to See Complete Forum and Search --> : [RESOLVED] Global array problem


Nibinaear
February 23rd, 2008, 11:14 AM
I'm trying to use an array from a file in my object oriented method, but it can't see it. I've tried making the array global but it makes no difference. If I try and print the array in the same file then it works, but methods can't see it.



class Gallery
{

public function __construct(){}

public function getRows($images)
{
global $gallery_rows;

foreach($galery_rows as $r=>$s)
{
if($images>=$galery_rows[$r]['lower'] && $images<=$galery_rows[$r]['upper'])
{
return $galery_rows[$r]['rows'];
}
}
}

}

$gallery_rows is declared in a separate file but I know it has been included right. My error is:

Notice: Undefined variable: galery_rows in C:\webpages\rspca\classes\Gallery.php on line 32

PeejAvery
February 23rd, 2008, 01:51 PM
Well, off hand I would say you might want to correct the spelling. You use both $gallery_rows and $galery_rows.

EDIT: Fixed the bold tags.

Nibinaear
February 24th, 2008, 08:06 AM
Crap. I actually copied and pasted in the name of the gallery rows to the global bit just to make sure that it wasn't spelling, but for some reason never bothered to do the same in the function. Well at least it's fixed. Thanks for what its worth.