Archived

This topic is now archived and is closed to further replies.

Arrays of Classes in PHP

This topic is 5332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can someone please explain how you can create an array of classes in PHP? I have a while loop that should add a class with data in it into an array every iteration. The way I add stuff into the array is this
$Fields = new EditField;
$Fields[i]->Name = $result_array['Field'];
  
Later on in the same while loop I have this (I added it as a test)
echo $Fields[i]->Name;
echo "< BR >";
echo $Fields[i]->Hidden;
echo "< BR >";
echo $Fields[i]->Type;
echo "< BR >";
  
Hidden and Type are both other variables in the class. This echo's out all the data correctly. Now later on in the script (that lot was before the tag this next bit is in the </body> tags) I have this
for($i = 0;$i < $ArraySize;$i++)
{
	printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>", $Fields[$i]->Type, $Fields[$i]->Name, $Fields[$i]->Hidden);
}
  
$ArraySize is set correctly and everything but for some $Fields[$i]->Type, $Fields[$i]->Name and $Fields[$i]->Hidden all have nothing in them. Can anyone tell me what's going wrong here?
[edit]Fixed < br > formatting (in the real code there aren't any spaces in the tag[/edit] [edited by - Monder on May 7, 2003 6:59:33 PM]

Share this post


Link to post
Share on other sites
I've just realised that I should be using

$Fields = new EditField;
$Fields[$i]->Name = $result_array['Field'];


and

echo $Fields[$i]->Name;echo "< BR >";
echo $Fields[$i]->Hidden;
echo "< BR >";
echo $Fields[$i]->Type;echo "< BR >";


But when I do that the array still doesn't get filled. I must be doing something wrong. Can someone tell me what it is?

[edited by - Monder on May 8, 2003 1:36:55 PM]

Share this post


Link to post
Share on other sites