【发布时间】:2020-03-19 21:39:34
【问题描述】:
我在控制器中调用了这样的函数:
$all_calendars = Appointment::organizeAppointment($daysView['currentDay']['appointments'], $openingHours);
经过长时间的计算,包括几个查询,它返回一个像这样的集合:
return $appointments;
$appointments 的内容如下所示:
appointments:1 [▼
"Employee1" => array: [▼
"08:00" => ""
"08:15" => ""
"08:30" => ""
"08:45" => ""
"09:00" => Appointment {#11949 ▶}
"09:15" => "Ja"
"09:30" => "Ja"
"09:45" => "Ja"
"10:00" => Appointment {#11950 ▶}
"10:15" => "Ja"
"10:30" => "Ja"
"10:45" => "Ja"
"11:00" => ""
"11:15" => ""
"11:30" => ""
"11:45" => ""
"12:00" => Appointment {#11952 ▶}
"12:15" => "Ja"
"12:30" => "Ja"
"12:45" => "Ja"
"13:00" => Appointment {#11953 ▶}
"13:15" => "Ja"
"13:30" => "Ja"
"13:45" => "Ja"
"14:00" => Appointment {#11954 ▶}
"14:15" => "Ja"
"14:30" => "Ja"
"14:45" => "Ja"
"15:00" => Appointment {#11955 ▶}
"15:15" => "Ja"
"15:30" => "Ja"
"15:45" => "Ja"
"16:00" => Appointment {#11956 ▶}
"16:15" => "Ja"
"16:30" => "Ja"
"16:45" => "Ja"
"17:00" => ""
],
"Employee2" => array: [],
"Employee3" => array: [],
"Employee4" => array: [],
...
]
现在我想知道每个员工有多少约会,这只是进一步添加所有约会的一步:
$totalPerEmployee[$name] = count(array_filter($all_calendars));
在上面显示的情况下,employee1 将有 7 个。
但我不想调用同一个进程,而且我不能将此值添加到每个员工子集合的末尾,因为它会破坏前端的“foreach”。
所以我决定创建这个值并将其存储在第二个数组中,如下所示:
totals:1 [▼
"Employee1" => array: [▼
"total" => 7
],
"Employee2" => array: [
"total = 4
],
"Employee3" => array: [],
"Employee4" => array: [],
...
]
我的问题是我现在如何从一个函数返回两个值?
我在 PHP 中这样说:
return ($appointments and $totals); ///<--- of course this is not valid PHP
只需一次通话。
【问题讨论】: