Example: $ I = [number]; print the following figure: 12341213145111615610987/*** two-dimensional array sorting * @ paramarray $ array */functionsort_recursive ($ array) {foreach ($ arrayas $ key = example:
$ 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
- * @ Param array $ array
- */
- Function sort_recursive (& $ array ){
- Foreach ($ array as $ key => $ edge ){
- Ksort ($ edge, true );
- $ Array [$ key] = $ edge;
- }
- Ksort ($ array, true );
- }
- /**
- * Generate a ring number
- * @ Param array $ cotainer two-dimensional array, containing the generated circle
- * @ Param int $ start_value start value of the circle
- * @ Param int $ x offset of the circle
- * @ Param int $ number of digits on each edge of grids_edge
- */
- Function generate (& $ container, $ start_value, $ x, $ grids_edge ){
- $ Rec_times = ceil ($ grids_edge/2 );
- $ Center = $ grids_edge & 1? False: $ start_value + 4 * $ rec_times * ($ rec_times + 1 );
- If ($ center ){
- $ Index = $ x + ceil ($ grids_edge/2 );
- $ Container [$ index] [$ index] = $ center;
- }
- For ($ I = 0; $ I <$ grids_edge; $ I ++ ){
- $ Right = $ x + $ grids_edge;
- $ Basevalue = $ start_value + $ I;
- $ Container [$ x] [$ x + $ I] = $ base_value;
- $ Container [$ x + $ I] [$ right] = $ grids_edge + $ base_value;
- $ Container [$ right] [$ right-$ I] = $ grids_edge * 2 + $ base_value;
- $ Container [$ right-$ I] [$ x] = $ grids_edge * 3 + $ base_value;
- }
- }
- $ Container = array ();
- $ Data = array (
- 1 => array (1, 6 ),
- 25 => array (2, 4 ),
- 41 => array (3, 2 ),
- );
- /*
- $ Data = array (
- 1 => array (1, 2 ),
- );
- $ Data = array (
- 1 => array (1, 5 ),
- 21 => array (2, 3 ),
- 33 => array (3, 1 ),
- );
- $ Data = array (
- 1 => array (1, 3 ),
- 13 => array (2, 1 ),
- );
- */
- Foreach ($ data as $ key => $ val ){
- Generate ($ container, $ key, $ val [0], $ val [1]);
- }
- Sort_recursive ($ container );
- $ Table ='
';
- Foreach ($ container as $ key => $ edge ){
- $ Table. ='';
- Foreach ($ edge as $ val ){
- $ Table. =''. $ Val .'';
- }
- $ Table. ='';
- }
- $ Table. ='';
- Echo $ table;