在我的自定义Moodle plugin
中,我为每个日期获取车库,他们已预订,所以我应该有一个这样的列表:
Date1 - Garage 1
Date2 - Garage 2
Date3 - Garage 2
如您所见,一个车库可以在不同的日期重复。
我用这段代码得到车库名称:
$garagenames = array();
foreach ($garage as $rawgarage) {
$venue = array();
if (!empty($rawgarage->building)) {
$venue[] = $rawgarage->building;
}
if (!empty($rawgarage->address)) {
$venue[] = $rawgarage->address;
}
$garagename = implode(', ', $venue);
$garagenames[] = $garagename;
}
function _remove_empty_internal($value) {
return strlen($value)>1;
}
function remove_empty($array) {
return array_filter($array, '_remove_empty_internal');
}
$dates_arr_clean = remove_empty($allsessiondates);
$rooms_arr_clean = remove_empty($garagenames);
$rooms_arr = array();//explode("/n", $garages);
$datesgarages = "";
foreach ($dates_arr_clean as $date) {
if($garages_arr_clean)
$datesgarages .= $date . " - " . array_shift($garages_arr_clean) . "<br />";
else
$datesgarages .= $date . "<br />";
}
$rawgarage
的var_dump是:
(stdClass)#65 (10) { ["id"]=> string(1) "2" ["name"]=> string(8) "Garage1" ["building"]=> string(18) "HQ" ["address"]=> string(14) "1 Times Square" ["capacity"]=> string(2) "1" ["type"]=> string(8) "internal" ["description"]=> string(0) "" ["custom"]=> string(1) "0" ["timecreated"]=> string(10) "1458557926" ["timemodified"]=> string(10) "1459842497" }
问题是重复值没有显示,所以我们变成:
Date1 - Garage 1
Date2 - Garage 2
Date3 - **missing** (Garage 2)
我在代码中缺少什么才能显示重复值?