Php empty array randomly inserts this post and is finally edited by mahuatengBC from 2012-12-1712: 50: 13. suppose there is an empty array of 1000 elements, now we want to randomly insert 5 first prizes, randomly insert 10 second prizes, and randomly insert 20 third prizes. The rest are not winning. that is to say, these one thousand elements must have 5 First Prizes & nbsp; 10 Second Prizes & nbsp; 20 third prizes & php empty array random insertion
This post was last edited by mahuatengBC at 12:50:13, January 17 ,.
Example
Suppose there is an empty array of 1000 elements. now we want to randomly insert 5 first prizes, randomly insert 10 second prizes, and randomly insert 20 third prizes. The rest are not winning.
That is to say, these one thousand elements must have 5 first prizes, 10 second prizes, 20 third prizes, and others not winning.
How can this problem be achieved?
------ Solution --------------------
$ Ar = array_merge (array_fill (0, 5, 1), array_fill (0, 10, 2), array_fill (0, 20, 3), array_fill (0,965, 0 ));
Shuffle ($ ar );
$ Ar is the array you need