Arrays and classes.

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
fromzie
Forum Newbie
Posts: 1
Joined: Tue Dec 09, 2003 9:12 pm
Location: brisbane, australia
Contact:

Arrays and classes.

Post 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.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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];
Post Reply