PHP many objects with one Class

I'm very new with PHP and OOP techniques.

So I have no problem creating a object like so:

$member1 = new Member('person 1');

But is there a way to return a bunch of objects. So that I can iterate through them and put them in the DOM?

Answers


class Example
{
    public function getPeople()
    {
        $objs = array();
        for($i = 0; $i < 10; $i++)
        {
            $obj[] = new Person('Person ' . ($i + 1));
        }
        return $objs; // returning an array of Person objects
    }
}
$example = new Example();
foreach($example->getPeople() as $person)
{
    // Do something with $person
}

Need Your Help

Simple way to draw a collection of points

c# .net image drawimage

Is there any built in way to draw a collection of points? Currently I'm doing it like this:

Java Anomaly in Simple Context

java

I'm encountering a very strange anomaly in the run() method of a thread.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.