->add('bill', EntityType::class, [
'class' => \App\Entity\Bill::class,
'attr' => [
'class' => "js-example-basic-single",
],
'label' => false,
'required' => true,
'choice_label' => function ($bill) {
$sumPrice = 0;
$sumPayment = 0;
foreach ($bill->getCost() as $item) {
$sumPrice = $sumPrice + $item->getPrice();
foreach ($bill->getPayment() as $pay) {
$sumPayment = $sumPayment + $pay->getMoney();
}
$sum = $sumPayment - $sumPrice;
if ($sum != 0) {
return
$bill->getPlayers()->getName() . " " .
$sum;
}
}
}
]);
一切正常,我只得到总和等于0的玩家,其余的玩家,我没有玩家的名字(没关系),但是我有空格,而且我不知道如何删除它