Page 1 of 1

arrays in classes?

Posted: Wed Mar 31, 2004 3:29 pm
by mudkicker
well what i wanna ask is this:

Code: Select all

<?php
class foo {

var $var = array();

function addelement($elm) {

$this->var[] = $elm;

}

}

can we do something like that?

i want to add an array as a var in class and add elements to it in a function.

thanks.
?>

Posted: Wed Mar 31, 2004 3:44 pm
by pickle
Ya, you should be able to do that.

Posted: Wed Mar 31, 2004 3:45 pm
by markl999
Yes, you can. :o

Posted: Wed Mar 31, 2004 4:04 pm
by mudkicker
thanks people.

Posted: Wed Mar 31, 2004 4:05 pm
by mudkicker
btw should ve declare that array as

var $var = array();

or is only var $var enough?

Posted: Wed Mar 31, 2004 4:07 pm
by markl999
Either will work but var $var = array(); would be more 'correct'

Posted: Wed Mar 31, 2004 4:13 pm
by mudkicker
ok thanks.