Advertisement
Guest User

Untitled

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