Arrays of objects
| From: | Daniel Fairs | Date: | Wed, 11 Apr 2001 15:54:13 +0000 |
| Subject: | Arrays of objects | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-48179@lists.php.net to get a copy of this message | ||
Hi,
PHP provides a number of array-related functions which rely on a relation
existing between each array element. This is easy to understand for
primitive types (integers, strings and so on) but how does it work for
objects?
For example, I have a class Person. I have a number of Person objects in an
array. How do I define how a Person object is 'equal' to another, for the
purposes of searching through the array? Or would it be better to write a
Collection class, encapsulating an array (or some other storage structure),
which used callbacks in the Person class to determine equality, much in the
way the Java equals() method works?
Thanks,
Dan