Page 1 of 1

Arrays and classes.

Posted: Tue Dec 09, 2003 9:12 pm
by fromzie
Hi,
I'm having troubles with creating an array within a class. There's no problem doing it elsewhere, it's just inside a class.

I start off by making the class

Code: Select all

class Name {


I then declare a few variables,

Code: Select all

var $something;
I then have a function, which then creates an array, and echos it.

Code: Select all

function name() {
        	    $this->array = array(1 => 'a','b','c');
                    echo $this->array[1];
	}
Then of course, I end the class.

Code: Select all

}
Nothing happens when I call the function within the class. I've verified i'm calling the function correctly by adding

Code: Select all

echo "test";
to the function.

If anyone can point out what i'm doing wrong, it'd be greatly appreciated.

I've checked the manual, google'd it -> What am I missing???

Thanks.

Posted: Tue Dec 09, 2003 10:36 pm
by Sevengraff
Maybe if you have

Code: Select all

$this->array = array(1 => 'a', 2 => 'b', 3 => 'c');
instead of just

Code: Select all

$this->array = array(1 => 'a','b','c');
Or even simpler

Code: Select all

$this->array = array('a','b','c'); 
echo $this->array[0];