dayweeksunsession==1){ $daysUsed .= "S-6ren">
gpt4 book ai didi

php - 除了最后一个以外,天数都用逗号显示

转载 作者:太空宇宙 更新时间:2023-11-04 13:43:58 25 4
gpt4 key购买 nike

我有以下 if 语句,这些语句收集了在显示之前选择的所有日期。

$daysUsed = "";

if($this->dayweeksunsession==1){
$daysUsed .= "Su ";
}

if($this->dayweekmonsession==1){
$daysUsed .= "M ";
}

if($this->dayweektuessession==1){
$daysUsed .= "T ";
}

if($this->dayweekwedsession==1){
$daysUsed .= "W ";
}

if($this->dayweekthurssession==1){
$daysUsed .= "Th ";
}

if($this->dayweekfrisession==1){
$daysUsed .= "F ";
}

if($this->dayweeksatsession==1){
$daysUsed .= "Sa ";
}

if($daysUsed !=="") {
echo "</span><br/>Days of the Week: <span class='BoxReviewOutput'>";
echo $daysUsed;
}

我的问题是,我怎样才能做到这一点,以便在 session 中选择的一周中的每一天都显示逗号,最后一天除外。

例如:选择了星期日和星期二。所以会显示“Su, T”

提前致谢!

最佳答案

使用implode()

$days = array("Su", "M", ....., "Sa");
echo implode(",", $days);

关于php - 除了最后一个以外,天数都用逗号显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10111579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com