<?php
interface Named {
function getName(): string;
}
class Flower implements Named {
private $name = "";
function __construct($name) {
$this->name = $name;
}
function getName(): string {
return $this->name;
}
}
class City extends Flower {}
class Star extends Flower {}
$rows = [
new Flower("Rose"),
new City("Rome"),
new Star("Sirius")
];
$names = array_map(
function ($r) { return $r->getName(); }, $rows);
$list = implode(", ", $names);
//list is "Rose, Rome, Sirius"
echo $list;