PHP array problem

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

Post Reply
normishappy
Forum Newbie
Posts: 1
Joined: Wed Nov 19, 2003 8:38 am

PHP array problem

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you have $this->$info throughout your class-code. Replace it by $this->info
Post Reply