The problem here lies with the each function, I believe. I played with this for a minute
and that's where I ran into problems with unexpected behaviour. Regardless, I was able to
get expected functionality using foreach instead of the while loop. While foreach isn't
available in PHP3 it is in
I'm currently having a problem with another array in a class & I can't
figure it out -
class myClass
{
function myClass($arr = array( 'item1'=>array('a','b','c'),
'item2'=>array('a','b','c') ) )
{
print_r( $arr );
while( list($key,$val) = each($arr) )
{
---
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
&g
$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
> 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
5 matches
Mail list logo