在下面的函数中,我使用了两个相同的变量,因为里面是不同的语言,我需要帮助来替换这个变量$ periods [$ j]。=“”;
示例:
function showdate($time)
{
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$periods2 = array("seconds", "minutes", "hours", "days", "weeks", "months", "years", "decade");
$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)
{
**/* In this case i need to show me this variable $periods2 */**
$periods[$j].= "";
}
return "$difference $periods[$j] $tense";
}
答案 0 :(得分:1)
你可以写$periods[$j] = $periods2[$j]
,但我认为制作另一个变量更好。
function showdate($time){
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$periods2 = array("seconds", "minutes", "hours", "days", "weeks", "months", "years", "decade");
$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);
$pText = $periods[$j];
if($difference>1) $pText = $periods2[$j];
return "$difference $pText $tense";
}
答案 1 :(得分:0)
if($difference != 1)
{
$periods[$j] = $periods2[$j];
}
此外,您的句点中的十年数组缺少一个s。