Thanks, that solved the problem :) I am however now having another problem inside 1 of the class functions
function return_statement() { $state = $this->statement; print_r( $this->statement ); while( list($item,$arr) = each($this->statement) ) { print "Hello"; } /* while( list($item,$arr) = each($state) ) { print "Hello"; } */ } $this->statement prints out as Array { [a] => Array ( [0]=>"1", [1]=>"2", [2]=>"3", ), [b] => Array ( [0]=>"1", [1]=>"2", [2]=>"3", ) } For some reason the first while() does not print anything, but comment the first while() & let the 2nd run & it prints. What's up with this? Is this correct or am I missing something obvious again? Thanks again Patrick ----- Original Message ----- From: "James Holden" <[EMAIL PROTECTED]> To: "Patrick Teague" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Monday, March 10, 2003 4:01 AM Subject: Re: [PHP] dynamic/multidimensional arrays in classes > $this->$arr[] > > should be > > $this->arr[] > > You are using a variable defined within the class - since it is a class variable you can reference it as you would anything else within the class, using '$this->' > > > > > > Patrick Teague wrote: > > >I'm having problems figuring this out. This first way gives me a 'Fatal > >Error: Cannot use [] for reading in class.php on line xx' > > > >class myClass > >{ > > var $arr = array(); > > > > function add_something( $value ) > > { > > $this->$arr[] = $value; // this is the line causing the error > > } > >} > > > >I've also tried using count() to find out how many items are in $arr, but it > >keeps saying that $r == 0... i.e. > > > >function add_something( $value ) > >{ > > $r = count($arr); > >/* > > if( is_null( $r ) > > { > > $r = 0; > > } > >*/ > > //print( $r ); > > $this->$arr[$r] = $value; > >} > > > >I've tried this both with & without the commented section & still $r = 0 > >even if you use '$class->add_something("my value");' 50 times. I'm guessing > >once this problem is solved it will work for multidimensional arrays as > >well? > > > >Patrick > > > > > > > > > > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php