Interpreting PHP Bubble sequencing Tips _php Tutorial

Source: Internet
Author: User

PHP Bubble Sort program File sort_bubble_up.php

  1. < html>
  2. < head>< title> php bubble sequencing demo < /title>< head>
  3. < link rel = "stylesheet" href = "Sort.css" >
  4. < body>
  5. < H1> bubble sequencing demo < /h1>
  6. < table cellpadding = "5" cellspacing ="1"
    Border="0" align="center" >
  7. < ? PHP
  8. Randomly generated arrays
  9. $ arr = Array ();
  10. Echo ' < tr>< td colspan= " ten" class="title">
    Initial values < /td>< /tr > ';
  11. Echo ' < tr>';
  12. For ($i=0; $i< $i + +) {
  13. $arr [$i]=rand ();
  14. echo " < td>$arr [$i]={$arr [$i]}< /td > ";
  15. }
  16. To sort by bubbling
  17. For ($i=9; $i>0; $i-) {
  18. Echo ' < tr>< td colspan= " ten" class="title"> "
    . (10-$i). ' Times
    < /td>< /tr> ';
  19. For ($J=0; $j< $i; $j + +) {
  20. if ($arr [$j]< $arr [$j +1]) {
  21. $ tmp = $arr [$j];
  22. $arr [$j]= $arr [$j +1];
  23. $arr [$j +1]= $tmp;
  24. }
  25. Echo ' < tr>';
  26. for ($k=0; $k< ; $k + +) {
  27. Switch ($k) {
  28. Case $j: Echo ' < TD class="base">"; break;
  29. Case $j +1:echo ' < TD class="Light">";
  30. Default:echo ' < td>';
  31. }
  32. echo "$arr [$k]={$arr [$k]} < /td > ";
  33. }
  34. Echo ' < /tr > ';
  35. }
  36. }
  37. Show sort Results
  38. Echo ' < tr>< td colspan= " ten" class="title"> results < /td >< /tr > ';
  39. Echo ' < tr>';
  40. For ($i=0; $i< $i + +) {
  41. echo " < td>$arr [$i]={$arr [$i]}< /td > ";
  42. }
  43. Echo ' < /tr > ';
  44. ?>
  45. < /table >
  46. < /body >< /html >

PHP Bubble Sort style sheet file Sort.css

H1{text-align:center; color:blue;}
table{font-size:12px; font-family:arial; background-color:black; text-align:center;}
Td{background-color:white;}
. Base{background-color: #0FF;}
. Light{background-color: #0DD;}
. Title{background-color: #3FF; text-align:center;}


http://www.bkjia.com/PHPjc/445918.html www.bkjia.com true http://www.bkjia.com/PHPjc/445918.html techarticle php Bubble Sort program file sort_bubble_up.php HTML head title php bubble Sort Method Demo/title head link rel = stylesheet href = sort.css body h1 bubble row Sequencer demo/H1 Table cel ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.