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