首頁 >後端開發 >php教程 >PHP之10個整數,從小到大排序,輸出排序結果

PHP之10個整數,從小到大排序,輸出排序結果

WBOY
WBOY原創
2016-07-28 08:26:173175瀏覽

10個整數,從小到大排序,輸出排序結果

<code><span>$aray</span> = <span>array</span>(<span>5</span>,<span>4</span>,<span>3</span>,<span>2</span>,<span>6</span>,<span>7</span>,<span>9</span>,<span>8</span>,<span>1</span>,<span>10</span>);
 <span>for</span>(<span>$i</span>=<span>0</span>;<span>$i</span><count(<span>$aray</span>);<span>$i</span>++){
      <span>for</span>(<span>$j</span>=<span>$i</span>+<span>1</span>;<span>$j</span><count(<span>$aray</span>);<span>$j</span>++){
          <span>$a</span>=<span>$aray</span>[<span>$i</span>];
          <span>$b</span>=<span>$aray</span>[<span>$j</span>];
          <span>if</span>(<span>$a</span>><span>$b</span>){
            <span>$aray</span>[<span>$i</span>]=<span>$b</span>;
            <span>$aray</span>[<span>$j</span>]=<span>$a</span>;
          }

      }
 }
 <span>//输出排序好的</span><span>for</span>(<span>$k</span>=<span>0</span>;<span>$k</span><count(<span>$aray</span>);<span>$k</span>++){
    <span>echo</span><span>$aray</span>[<span>$k</span>].<span>','</span>;

  }
</code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了 PHP之10個整數,從小到大排序,輸出排序結果,包含了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn