PHP 将(th,st,nd,rd,th)添加到数字的末尾

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 将(th,st,nd,rd,th)添加到数字的末尾相关的知识,希望对你有一定的参考价值。

<?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;
} 
for($i=1;$i<100;$i++){
    echo ordinal($i).'<br>';
}

以上是关于PHP 将(th,st,nd,rd,th)添加到数字的末尾的主要内容,如果未能解决你的问题,请参考以下文章