Advertisement
koki2000

numbers to 2d arrays

Nov 5th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.78 KB | None | 0 0
  1. <?php
  2.  
  3. $numbers = array(53.27219 ,53.10959 ,52.94684 ,52.78391 ,52.62078
  4.  
  5. ,52.45744 ,52.29386 ,52.13 ,51.96584 ,51.80133 ,51.63642 ,51.47107 ,51.30519 ,51.13872
  6.  
  7. ,50.97154 ,50.80353 ,50.63453 ,50.46435 ,50.29274 ,50.11935 ,49.94374 ,49.76532
  8.  
  9. ,49.58325 ,49.39632 ,49.20276 ,48.99983 ,48.78312 ,48.54514 ,48.27245 ,47.9406
  10.  
  11. ,47.51787 ,46.98374 ,46.30088 ,45.34415 ,43.70032 ,40.38476 ,34.11288 ,24.58026
  12.  
  13. ,12.87396 ,0.219008 ,-12.751 ,-25.8118 ,-38.8813 ,-51.8813 ,-64.6077 ,-76.4788 ,-86.3479 ,-
  14.  
  15.     93.1662 ,-97.1914 ,-99.6282 ,-101.403 ,-102.901 ,-104.236 ,-105.44 ,-106.519 ,-107.441 ,-
  16.  
  17.     108.099 ,-108.315 ,-108.007 ,-107.299 ,-106.363 ,-105.293 ,-104.111 ,-102.809 ,-101.353 ,-
  18.  
  19.     99.6144 ,-97.1804 ,-93.1542 ,-86.5742 ,-77.5024 ,-66.9783 ,-55.9228 ,-44.7659 ,-33.6655 ,-
  20.  
  21.     22.7078 ,-12.0465 ,-2.16749 ,5.596392 ,8.953605 ,6.409632 ,-0.87122 ,-10.5532 ,-21.1423 ,-
  22.  
  23.     32.0684 ,-43.1543 ,-54.3139 ,-65.4137 ,-76.1186 ,-85.6619 ,-92.8141 ,-96.6372 ,-97.5276 ,-
  24.  
  25.     96.8456 ,-95.6864 ,-94.4844 ,-93.2892 ,-92.0474 ,-90.7437 ,-89.4553 ,-88.344 ,-87.5706 ,-
  26.  
  27.     87.1008 ,-86.4368 ,-84.4731 ,-79.7794 ,-71.3296 ,-59.1578 ,-44.4565 ,-29.2102 ,-15.6416 ,-
  28.  
  29.     5.46076 ,0.903399 ,4.35291 ,6.237021 ,7.487215 ,8.449697 ,9.134153 ,9.448294 ,9.276234
  30.  
  31. ,8.410266 ,6.415044 ,2.740944 ,0.903399 ,4.35291 ,6.237021 ,7.487215 ,8.449697
  32.  
  33. ,9.134153 ,9.276234 ,8.410266 ,6.415044 ,2.740944 ,0.903399, -2.6511 ,-9.06238 ,-15.7684
  34.  
  35. ,-22.4422 ,-29.0107 ,-35.4879 ,-41.93 ,-48.4198 ,-54.9181 ,-60.7777 ,-64.2487 ,-63.3878 ,-
  36.  
  37.     57.9984 ,-49.5176 ,-39.447 ,-28.7147 ,-17.855 ,-7.31229 ,2.28053 ,9.885485 ,14.29327
  38.  
  39. ,15.14748 ,13.47304 ,10.62232 ,7.356688 ,3.939311 ,0.45589 ,-3.00618 ,-6.20513 ,-8.55388
  40.  
  41. ,-9.25998 ,-8.09212 ,-5.69937 ,-2.93759 ,-0.37243 ,1.671892 ,2.884461 ,2.727444 ,0.28318
  42.  
  43. ,-5.57111 ,-15.4768 ,-28.7477 ,-43.1527 ,-55.6418 ,-63.5747 ,-65.8155 ,-63.0848 ,-57.2701 ,-
  44.  
  45.     50.2576 ,-43.2142 ,-36.5727 ,-30.3353 ,-24.3377 ,-18.3926 ,-12.3611 ,-6.18032 ,0.153234
  46.  
  47. ,6.619063 ,13.17661 ,19.69365 ,25.79519 ,30.81346 ,34.18413 ,35.98827 ,36.79111
  48.  
  49. ,37.09688 ,37.15755 ,37.05811 ,36.81298 ,36.39788 ,35.7003 ,34.34804 ,31.5164 ,26.29645
  50.  
  51. ,18.71088 ,9.715393 ,0.177027 ,-9.49762 ,-19.1638 ,-28.7514 ,-38.1497 ,-47.0191 ,-54.4243
  52.  
  53. ,-58.7291 ,-58.8152 ,-55.463 ,-50.3447 ,-44.5505 ,-38.5009 ,-32.3263 ,-26.0857 ,-19.8645 ,-
  54.  
  55.     13.8857 ,-8.65529 ,-4.83797 ,-2.62424 ,-1.50655 ,-0.89118 ,-0.47028 ,-0.13983 ,0.129811
  56.  
  57. ,0.349844 ,0.533673 ,0.69606 ,0.845594 ,0.986988 ,1.122951 ,1.255128 ,1.38457 ,1.511976
  58.  
  59. ,1.637826 ,1.762463 ,1.886135 ,2.00903 ,2.131288 ,2.253018 ,2.374305 ,2.495219
  60.  
  61. ,2.615814 ,2.736134 ,2.856217 ,2.976092 ,3.095786 ,3.21532 ,3.334712 ,3.453977 ,3.57313
  62.  
  63. ,3.692181 ,3.811141 ,3.930019 ,4.048821 ,4.167556 ,4.286228 ,4.404843 ,4.523406
  64.  
  65. ,4.641922 ,4.760393 ,4.878823 ,4.997215 ,5.115573 ,5.233898 ,5.352192 ,5.470459
  66.  
  67. ,5.588699 ,5.706914 ,5.825107 ,5.943277 ,6.061428 ,6.179559 ,6.297673 ,6.415769
  68.  
  69. ,6.53385 ,6.651915 ,6.769966 ,6.888004);
  70. function rendez(array $array)
  71. {
  72.     $output = [];
  73.     $positive = ($array[0] <= 0)?false:true;
  74.    
  75.     for($i = 0; $i < count($array); $i++)
  76.     {
  77.         if($array[$i] >= 0)
  78.         {
  79.             if($positive == true)
  80.             {
  81.                 array_push($output, [$array[$i]]);
  82.                 $positive = false;
  83.             }
  84.             else
  85.             {
  86.                 $length = count($output)-1;
  87.                 $temparray = $output[$length];
  88.                 $temparray[] = $array[$i];
  89.                 $output[$length] = $temparray;
  90.                
  91.             }
  92.         }
  93.         else if($array[$i] < 0)
  94.         {
  95.             if($positive == false)
  96.             {
  97.                 array_push($output, [$array[$i]]);
  98.                 $positive = true;
  99.             }
  100.             else
  101.             {
  102.                 $length = count($output)-1;
  103.                 $temparray = $output[$length];
  104.                 $temparray[] = $array[$i];
  105.                 $output[$length] = $temparray;
  106.             }
  107.         }
  108.     }
  109.    
  110.     return $output;
  111.    
  112. }
  113.  
  114. print '<pre>';
  115. var_dump( rendez($numbers) );
  116. print '</pre>';
  117.  
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement