fork download
  1. <?php
  2.  
  3. // your code goes here
  4. $amount_of_zero = rand(0, 4);
  5. $array = array_map(function() use (&$amount_of_zero) {
  6. return $amount_of_zero-- > 0 ? 0 : 1;},
  7. range(1, 10));
  8. shuffle($array);
  9. var_dump($array);
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
array(10) {
  [0]=>
  int(1)
  [1]=>
  int(1)
  [2]=>
  int(1)
  [3]=>
  int(0)
  [4]=>
  int(1)
  [5]=>
  int(1)
  [6]=>
  int(1)
  [7]=>
  int(1)
  [8]=>
  int(1)
  [9]=>
  int(1)
}