Page 1 of 1

PHP array problem

Posted: Wed Nov 19, 2003 8:38 am
by normishappy
I have created an array like so:

Code: Select all

$cust_contact = array(); 
   $cust_contactї"name"] = "My Name";



Then I pass that array into a constructor of my Email class:

Code: Select all

class Email { 
  var $info = array(); 

function Email($cust_info) { 
  $this->$info = $cust_info; 
  print_r($cust_info); 
  echo("<br>"); 
  print_r($this->$info); 

  echo("<br><br>name= ".$cust_info&#123;"name"&#125;); 
  echo("<br>name= ".$this->$info&#123;"name"&#125;); 
&#125;//constructor 

&#125;//class


I have printed out the structure of the each array as well as the values in each array above. Here is the output:

Code: Select all

Array ( &#1111;name] => My Name ) 
Array ( &#1111;name] => My Name ) 

name= My Name 
name= Array


If both arrays have the same structure ( [name] => My Name ), and I am accessing the values of those arrays in the exact same way ( name= ".$cust_info{"name"}); ), why don't they both print out "My Name" as the value instead of "Array"?

Thanks

Posted: Wed Nov 19, 2003 8:56 am
by volka
you have $this->$info throughout your class-code. Replace it by $this->info