PHP添加 th,st,nd 或者 rd 作为数字的后缀

添加 th,st,nd 或者 rd 作为数字的后缀

[code lang=”php”]
function ordinal($cdnl){
$test_c = abs($cdnl) % 10;
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? ‘th’
: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
? ‘th’ : ‘st’ : ‘nd’ : ‘rd’ : ‘th’));
return $cdnl.$ext;
}
[/code]

语法:
[code lang=”php”]
<?php
$number = 10;
echo ordinal($number); //output is 10th
?>

[/code]


已发布

分类

来自

标签:

0 0 投票数
文章评分
订阅评论
提醒
guest
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x