PHP print ring digital circles _ PHP Tutorial

Source: Internet
Author: User
PHP prints a ring number circle. Example: $ I [number]; print the following figure: 12341213145111615610987 *** two-dimensional array sorting * @ paramarray $ array * functionsort_recursive ($ array) {foreach ($ array as the title:
$ I = [number];
Print the following figure:

1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7

 
  1. /**
  2. * Two-dimensional array sorting
  3. * @ Param array $ array
  4. */
  5. Function sort_recursive (& $ array ){
  6. Foreach ($ array as $ key => $ edge ){
  7. Ksort ($ edge, true );
  8. $ Array [$ key] = $ edge;
  9. }
  10. Ksort ($ array, true );
  11. }
  12. /**
  13. * Generate a ring number
  14. * @ Param array $ cotainer two-dimensional array, containing the generated circle
  15. * @ Param int $ start_value start value of the circle
  16. * @ Param int $ x offset of the circle
  17. * @ Param int $ number of digits on each edge of grids_edge
  18. */
  19. Function generate (& $ container, $ start_value, $ x, $ grids_edge ){
  20. $ Rec_times = ceil ($ grids_edge/2 );
  21. $ Center = $ grids_edge & 1? False: $ start_value + 4 * $ rec_times * ($ rec_times + 1 );
  22. If ($ center ){
  23. $ Index = $ x + ceil ($ grids_edge/2 );
  24. $ Container [$ index] [$ index] = $ center;
  25. }
  26. For ($ I = 0; $ I <$ grids_edge; $ I ++ ){
  27. $ Right = $ x + $ grids_edge;
  28. $ Basevalue = $ start_value + $ I;
  29. $ Container [$ x] [$ x + $ I] = $ base_value;
  30. $ Container [$ x + $ I] [$ right] = $ grids_edge + $ base_value;
  31. $ Container [$ right] [$ right-$ I] = $ grids_edge * 2 + $ base_value;
  32. $ Container [$ right-$ I] [$ x] = $ grids_edge * 3 + $ base_value;
  33. }
  34. }
  35. $ Container = array ();
  36. $ Data = array (
  37. 1 => array (1, 6 ),
  38. 25 => array (2, 4 ),
  39. 41 => array (3, 2 ),
  40. );
  41. /*
  42. $ Data = array (
  43. 1 => array (1, 2 ),
  44. );
  45. $ Data = array (
  46. 1 &

    Crop $ I = [number]; print the following figure: 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7/*** two-dimensional array sorting * @ paramarray $ array */function sort_recursive ($ array) {foreach ($ array...

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.