我想从下面的代码中排除“ mois ”这个词,以防止在其中添加“s”。
function ago($time) {
$periods = array("seconde", "minute", "heure", "jour", "semaine", "mois", "année", "décade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "ago";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "Il y a $difference $periods[$j].";
}
答案 0 :(得分:3)
使用substr($periods[$j], -1)
,您将获得字符串中的最后一个字符,因此
if($difference != 1 && substr($periods[$j], -1) != 's') {
$periods[$j].= "s";
}