I have an array of objects and I want to convert it to an array of the result of a method of each of them. I can do this just fine, but I'm wondering if there is a cleaner / better approach to it maybe? For example, pretend this is what I'm working with and how I'm doing it now:
$objects = array();
$objects[] = new Dog();
$objects[] = new Dog();
$objects[] = new Dog();
$data = array();
foreach ($objects as $obj) {
$data[] = $obj->myMethod();
}
Obviously this isn't super important, but it'd be nice to know about better ways to produce $data from $objects in the future. Any ideas? I was thinking there was some function for this, like array_map() or something but I'm not finding it.