How to create an array of objects?
Posted: Mon Apr 14, 2008 3:42 am
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
consider the following :-
This gives me an error as "Parse error: syntax error, unexpected T_VARIABLE in C:\webs\test\object.php on line 9"
Can anyone tell me how to create an array of objects of the class Person??
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
consider the following :-
Code: Select all
<?php
class Person
{
var $name;
var $salary;
}
$p = array()
$p[0] = new Person;
$p[0]->name= "jax";
$p[0]->salary= 1000;
print_r($p[0]);
?>
Can anyone tell me how to create an array of objects of the class Person??
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: