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
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Mar 31, 2004 3:29 pm
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.
?>
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Wed Mar 31, 2004 3:44 pm
Ya, you should be able to do that.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Mar 31, 2004 3:45 pm
Yes, you can.
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Mar 31, 2004 4:04 pm
thanks people.
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Mar 31, 2004 4:05 pm
btw should ve declare that array as
var $var = array();
or is only var $var enough?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Mar 31, 2004 4:07 pm
Either will work but var $var = array(); would be more 'correct'
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Mar 31, 2004 4:13 pm
ok thanks.