问题描述
我想编写一些代码来判断我的日期是否需要st,nd rd或
。 />
虽然下面的代码有效,但我确信有更好的方法....
if(($ daterep ==" 1")| |($ daterep ==" 21")||($ daterep ==" 31")){
$ letters =" st";
} elseif(($ daterep ==" 2")||($ daterep ==" 22")){
$ letters =" nd";
} elseif(($ daterep ==" 3")||($ daterep ==" 23")){
$ letters =" rd";
} else {
$ letters =" th";
}
我试过:
if($ daterep ==" 1" ||" 21" ||" 31"){... etc
但它没有工作...虽然我不明白为什么?
我把$ daterep投入一个字符串,但现在我发现我可以把它留下来
一个人... ..
任何建议如何让这段代码更顺畅?
Robert
Hi,
I was wanting to write some code to work out whether I needed st, nd rd or
th in my dates.
While the code below works, I am certain that there is a better way....
if (($daterep == "1") || ($daterep == "21") || ($daterep == "31")){
$letters = "st";
} elseif (($daterep == "2") || ($daterep == "22")){
$letters = "nd";
} elseif (($daterep == "3") || ($daterep == "23")){
$letters = "rd";
} else {
$letters = "th";
}
I tried:
if ($daterep == "1" || "21" || "31") { ... etc
but it did not work... I don''t understand why though?
I cast $daterep into a string, but now I find that I could have left it
alone....
Any suggestions as to how to get this code working a bit smoother?
Robert
推荐答案
这篇关于必须有更好的方法来写这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!