Re: dynamic/multidimensional arrays in classes

From: Date: Thu, 13 Mar 2003 04:37:35 +0000
Subject: Re: dynamic/multidimensional arrays in classes
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-139435@lists.php.net to get a copy of this message
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" <php_lists@globalvision.com> To: "Patrick Teague" <webdude@veslach.com> Cc: <php-general@lists.php.net> 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 > > > > > > > > > > > > > > >

« previous php.general (#139435) next »