I want to create a <select> field from all Gender objects. Is there a way to iterate over all the objects created from the class of Gender?
class Gender {
public static $counter = 0;
public $id;
public $gender;
public function __construct($gender){
Gender::$counter++;
$this->id = Gender::$counter;
$this->gender = $gender;
}
}
// Objects
$gender_male = new Gender('Male');
$gender_female = new Gender('Female');
I understand now that it’s an extreme overkill to use a class but for the sake of knowing how it’s done, here’s the new code (based on all your comments):
It’s a group achievement in its own way but I think I’ll switch to arrays instead. 🙂