我有三个类:Transport,ServiceStation,CatalogTransport:
$service1=new ServiceStation('Service1','Address1');
$service2=new ServiceStation('Service2','Address2');
$t1=new Transport("t1",'type1',100,'carcase1','engine1','chassis1',$service1);
$t2=new Transport("t2",'type2',200,'carcase2','engine2','chassis2',$service1);
$t3=new Transport("t3",'type3',300,'carcase3','engine3','chassis3',$service2);
$catalog=new CatalogTransport();
$catalog->addTransport($t1);
$catalog->addTransport($t2);
$catalog->addTransport($t3);
$catalog->showCatalog();
我的CatalogTranspot课程:
class CatalogTransport{
private $catalog = [];
public function addTransport(Transport $t) {
$this->catalog[] = $t;
}
public function showCatalog() {
echo '<pre>';
print_r($this->catalog);
echo '</pre>';
}
}
我的showCatalog()返回:
Array
(
[0] => Transport Object
(
[name:Transport:private] => t1
[type:Transport:private] => type1
[weight:Transport:private] => 100
[carcase:Transport:private] => carcase1
[engine:Transport:private] => engine1
[chassis:Transport:private] => chassis1
[service:Transport:private] => ServiceStation Object
(
[name:ServiceStation:private] => Service1
[address:ServiceStation:private] => Address1
)
)
[1] => Transport Object
(
[name:Transport:private] => t2
[type:Transport:private] => type2
[weight:Transport:private] => 200
[carcase:Transport:private] => carcase2
[engine:Transport:private] => engine2
[chassis:Transport:private] => chassis2
[service:Transport:private] => ServiceStation Object
(
[name:ServiceStation:private] => Service1
[address:ServiceStation:private] => Address1
)
)
[2] => Transport Object
(
[name:Transport:private] => t3
[type:Transport:private] => type3
[weight:Transport:private] => 300
[carcase:Transport:private] => carcase3
[engine:Transport:private] => engine3
[chassis:Transport:private] => chassis3
[service:Transport:private] => ServiceStation Object
(
[name:ServiceStation:private] => Service2
[address:ServiceStation:private] => Address2
)
)
)
如何通过现场服务对其进行分组?
我希望它会这样:
服务1:
T1,T2
服务2: t3
如何解决我的问题?