dbillings Posted June 22, 2008 Share Posted June 22, 2008 I'm setting up my class variables as an array ($text['label'], $text['type'] etc...). Then I'm creating the object in another class and saving the object to another array $input. When I loop through the $input array the object prints... <label>Array['label']</label><input type='Array['type']' id='Array['id]' name='Array['name']' value='Array['value']'><label>Array['label']</label><input type='Array['type']' id='Array['id]' name='Array['name']' value='Array['value']'> It doesn't seem to recognize my assciative indexs I created. Any ideas why? Here's the full code <?php #Form Class 6/20/08 #Last Edit class Form { var $data; var $input=array(); public function Form ($name, $id, $method, $action) { $this->data['name']= $name; $this->data['id']= $id; $this->data['method']= $method; $this->data['action']= $action; } public function add_Input($label, $name, $id, $type, $value) { $this->input[]= new Text($label, $name, $id, $type, $value); } public function create_Form() { foreach($this->input as $value){ echo "<label>$value->text['label']</label><input type='$value->text['type']' id='$value->text['id]' name='$value->text['name']' value='$value->text['value']'>"; } } } Class Text extends Form { var $text; public function Text($label, $name, $id, $type, $value) { $this->text['label']= $label; $this->text['name']= $name; $this->text['id']= $id; $this->text['type']= $type; $this->text['value']= $value; } } $registration_form= new Form("Name", "ID", "post", $_SERVER['PHP_SELF']); $registration_form->add_Input("Name", "name", "ID", "text","Name"); $registration_form->add_Input("Age", "age", "ID", "text","Age"); $registration_form->create_Form(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/111381-solved-index-getting-lost-php-4/ Share on other sites More sharing options...
corbin Posted June 22, 2008 Share Posted June 22, 2008 Try changing... echo "<label>$value->text['label']</label><input type='$value->text['type']' id='$value->text['id]' name='$value->text['name']' value='$value->text['value']'>"; To echo "<label>{$value->text['label']}</label><input type='{$value->text['type']}' id='{$value->text['id]}' name='{$value->text['name']}' value='{$value->text['value']}'>"; Quote Link to comment https://forums.phpfreaks.com/topic/111381-solved-index-getting-lost-php-4/#findComment-571757 Share on other sites More sharing options...
dbillings Posted June 22, 2008 Author Share Posted June 22, 2008 Thankyou. Quote Link to comment https://forums.phpfreaks.com/topic/111381-solved-index-getting-lost-php-4/#findComment-571764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.