Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. // Crea dos arrays que se rellenen con los numeros del ARRAY principal, alternando los puestos
  4.  
  5. srand ((double)microtime()*1000000);
  6.  
  7. for($i=0; $i<10; $i++){
  8. $ar[$i]=rand(1,100);
  9. }
  10.  
  11. $tope=count($ar);
  12.  
  13. for($i=0; $i<$tope; $i++){
  14. echo $ar[$i]." ";
  15. }
  16.  
  17. echo "<br/>";
  18.  
  19. $x = 0;
  20. $y = 0;
  21.  
  22. for($i=0; $i<$tope; $i++){
  23. if($i % 2 == 0){
  24. $ar2[$x] = $ar[$i];
  25. $x++;
  26. }
  27. else {
  28. $ar3[$y] = $ar[$i];
  29. $y++;
  30. }
  31. }
  32.  
  33. for($i=0; $i<$x; $i++){
  34. echo $ar2[$i]." ";
  35. }
  36.  
  37. echo "<br/>";
  38.  
  39. for($i=0; $i<$y; $i++){
  40. echo $ar3[$i]." ";
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement