PHP正確的使用複數

來源:互聯網
上載者:User
  1 php  2// 正確地顯示複數  3if(!function_exists('_plurals_format'))  4{  5/**  6     * 正確的使用複數      7     * @access   public  8     * @author   zhaoyingnan   2016-02-17 11:53  9     * @param    string        $sPluralName    非複數形式的名稱 10     * @param    int           $iAmount        數量 11     * @return   string 12     * @note     13     **/ 14function _plurals_format($sPluralName, $iAmount) 15    { 16if(!$sPluralName || !is_numeric($iAmount) || $iAmount <= 0) 17return ''; 18// 特殊的複數形式 19$arPluralName = array( 20             'addendum'=>'addenda', 21             'alga'=>'algae', 22             'alumna'=>'alumnae', 23             'alumnus'=>'alumni', 24             'analysis'=>'analyses', 25             'antenna'=>'antennas',//antennae 26             'apparatus'=>'apparatuses', 27             'appendix'=>'appendices',//appendixes 28             'axis'=>'axes', 29             'bacillus'=>'bacilli', 30             'bacterium'=>'bacteria', 31             'basis'=>'bases', 32             'beau'=>'beaux', 33             'bison'=>'bison', 34             'buffalo'=>'buffalos',//buffaloes 35             'bureau'=>'bureaus', 36             'bus'=>'busses',//buses 37             'cactus'=>'cactuses',//cacti 38             'calf'=>'calves', 39             'child'=>'children', 40             'corps'=>'corps', 41             'corpus'=>'corpora',//corpuses 42             'crisis'=>'crises', 43             'criterion'=>'criteria', 44             'curriculum'=>'curricula', 45             'datum'=>'data', 46             'deer'=>'deer', 47             'die'=>'dice', 48             'dwarf'=>'dwarfs',//dwarves 49             'diagnosis'=>'diagnoses', 50             'echo'=>'echoes', 51             'elf'=>'elves', 52             'ellipsis'=>'ellipses', 53             'embargo'=>'embargoes', 54             'emphasis'=>'emphases', 55             'erratum'=>'errata', 56             'fireman'=>'firemen', 57             'fish'=>'fish',//fishes 58             'focus'=>'focuses', 59             'foot'=>'feet', 60             'formula'=>'formulas', 61             'fungus'=>'fungi',//funguses 62             'genus'=>'genera', 63             'goose'=>'geese', 64             'half'=>'halves', 65             'hero'=>'heroes', 66             'hippopotamus'=>'hippopotami',//hippopotamuses 67             'hoof'=>'hoofs',//hooves 68             'hypothesis'=>'hypotheses', 69             'index'=>'indices',//indexes 70             'knife'=>'knives', 71             'leaf'=>'leaves', 72             'life'=>'lives', 73             'loaf'=>'loaves', 74             'louse'=>'lice', 75             'man'=>'men', 76             'matrix'=>'matrices', 77             'means'=>'means', 78             'medium'=>'media', 79             'memorandum'=>'memoranda', 80             'millennium'=>'millenniums',//milennia 81             'moose'=>'moose', 82             'mosquito'=>'mosquitoes', 83             'mouse'=>'mice', 84             'nebula'=>'nebulae',//nebulas 85             'neurosis'=>'neuroses', 86             'nucleus'=>'nuclei', 87             'oasis'=>'oases', 88             'octopus'=>'octopi',//octopuses 89             'ovum'=>'ova', 90             'ox'=>'oxen', 91             'paralysis'=>'paralyses', 92             'parenthesis'=>'parentheses', 93             'person'=>'people', 94             'phenomenon'=>'phenomena', 95             'potato'=>'potatoes', 96             'radius'=>'radii',//radiuses 97             'scarf'=>'scarfs',//scarves 98             'self'=>'selves', 99             'series'=>'series',100             'sheep'=>'sheep',101             'shelf'=>'shelves',102             'scissors'=>'scissors',103             'species'=>'species',104             'stimulus'=>'stimuli',105             'stratum'=>'strata',106             'syllabus'=>'syllabi',//syllabuses107             'symposium'=>'symposia',//symposiums108             'synthesis'=>'syntheses',109             'synopsis'=>'synopses',110             'tableau'=>'tableaux',111             'that'=>'those',112             'thesis'=>'theses',113             'thief'=>'thieves',114             'this'=>'these',115             'tomato'=>'tomatoes',116             'tooth'=>'teeth',117             'torpedo'=>'torpedoes',118             'vertebra'=>'vertebrae',119             'veto'=>'vetoes',120             'vita'=>'vitae',121             'watch'=>'watches',122             'wife'=>'wives',123             'wolf'=>'wolves',124             'woman'=>'women',125             'zero'=>'zeros',//zeroes126        );127128// 如果只有一個129if($iAmount == 1)130return$sPluralName;131132// 如果超過一個,並且是特殊的複數形式133if(isset($arPluralName[$sPluralName]))134return$arPluralName[$sPluralName];135136// 超過一個,並且是一個標準的複數形式137return$sPluralName.'s';138    }139}140141echo 'Sybil ate three '._plurals_format('biscuit', 3).', one after the other.',PHP_EOL;142echo 'The two '._plurals_format('woman', 2).' will meet tomorrow in the final.';

以上就介紹了PHP正確的使用複數,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.