<small id='DHDQO'></small><noframes id='DHDQO'>

      <legend id='DHDQO'><style id='DHDQO'><dir id='DHDQO'><q id='DHDQO'></q></dir></style></legend>

        <tfoot id='DHDQO'></tfoot>
          <bdo id='DHDQO'></bdo><ul id='DHDQO'></ul>

        <i id='DHDQO'><tr id='DHDQO'><dt id='DHDQO'><q id='DHDQO'><span id='DHDQO'><b id='DHDQO'><form id='DHDQO'><ins id='DHDQO'></ins><ul id='DHDQO'></ul><sub id='DHDQO'></sub></form><legend id='DHDQO'></legend><bdo id='DHDQO'><pre id='DHDQO'><center id='DHDQO'></center></pre></bdo></b><th id='DHDQO'></th></span></q></dt></tr></i><div id='DHDQO'><tfoot id='DHDQO'></tfoot><dl id='DHDQO'><fieldset id='DHDQO'></fieldset></dl></div>

        在 PHP 中显示带序号后缀的数字

        Display numbers with ordinal suffix in PHP(在 PHP 中显示带序号后缀的数字)
          <tbody id='E2ZZv'></tbody>

        <tfoot id='E2ZZv'></tfoot>
      1. <i id='E2ZZv'><tr id='E2ZZv'><dt id='E2ZZv'><q id='E2ZZv'><span id='E2ZZv'><b id='E2ZZv'><form id='E2ZZv'><ins id='E2ZZv'></ins><ul id='E2ZZv'></ul><sub id='E2ZZv'></sub></form><legend id='E2ZZv'></legend><bdo id='E2ZZv'><pre id='E2ZZv'><center id='E2ZZv'></center></pre></bdo></b><th id='E2ZZv'></th></span></q></dt></tr></i><div id='E2ZZv'><tfoot id='E2ZZv'></tfoot><dl id='E2ZZv'><fieldset id='E2ZZv'></fieldset></dl></div>
        <legend id='E2ZZv'><style id='E2ZZv'><dir id='E2ZZv'><q id='E2ZZv'></q></dir></style></legend>

          <small id='E2ZZv'></small><noframes id='E2ZZv'>

              • <bdo id='E2ZZv'></bdo><ul id='E2ZZv'></ul>

                  本文介绍了在 PHP 中显示带序号后缀的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想如下显示数字

                  • 1 为 1,
                  • 2 次,
                  • ...,
                  • 150 为 150.

                  我应该如何为代码中的每个数字找到正确的序数后缀(st、nd、rd 或 th)?

                  How should I find the correct ordinal suffix (st, nd, rd or th) for each number in my code?

                  推荐答案

                  来自维基百科:

                  $ends = array('th','st','nd','rd','th','th','th','th','th','th');
                  if (($number %100) >= 11 && ($number%100) <= 13)
                     $abbreviation = $number. 'th';
                  else
                     $abbreviation = $number. $ends[$number % 10];
                  

                  其中 $number 是您要写入的数字.适用于任何自然数.

                  Where $number is the number you want to write. Works with any natural number.

                  作为一个函数:

                  function ordinal($number) {
                      $ends = array('th','st','nd','rd','th','th','th','th','th','th');
                      if ((($number % 100) >= 11) && (($number%100) <= 13))
                          return $number. 'th';
                      else
                          return $number. $ends[$number % 10];
                  }
                  //Example Usage
                  echo ordinal(100);
                  

                  这篇关于在 PHP 中显示带序号后缀的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Converting between timezones in PHP(在 PHP 中的时区之间转换)
                  PHP - strtotime, specify timezone(PHP - strtotime,指定时区)
                  Get current date, given a timezone in PHP?(获取当前日期,给定 PHP 中的时区?)
                  List of US Time Zones for PHP to use?(PHP 使用的美国时区列表?)
                  How to detect Ambiguous and Invalid DateTime in PHP?(如何在 PHP 中检测不明确和无效的 DateTime?)
                  How to update timezonedb in PHP (updating timezones info)?(如何在 PHP 中更新 timezonedb(更新时区信息)?)

                  1. <small id='9DuBd'></small><noframes id='9DuBd'>

                      <tbody id='9DuBd'></tbody>
                    • <bdo id='9DuBd'></bdo><ul id='9DuBd'></ul>

                        <i id='9DuBd'><tr id='9DuBd'><dt id='9DuBd'><q id='9DuBd'><span id='9DuBd'><b id='9DuBd'><form id='9DuBd'><ins id='9DuBd'></ins><ul id='9DuBd'></ul><sub id='9DuBd'></sub></form><legend id='9DuBd'></legend><bdo id='9DuBd'><pre id='9DuBd'><center id='9DuBd'></center></pre></bdo></b><th id='9DuBd'></th></span></q></dt></tr></i><div id='9DuBd'><tfoot id='9DuBd'></tfoot><dl id='9DuBd'><fieldset id='9DuBd'></fieldset></dl></div>
                        • <tfoot id='9DuBd'></tfoot>
                          <legend id='9DuBd'><style id='9DuBd'><dir id='9DuBd'><q id='9DuBd'></q></dir></style></legend>