The M algorithm selected by PHPN cannot be printed out in a large array.
Function Combination ($ sort, $ num) {$ result = $ data = array (); if ($ num = 1) {return $ sort ;} foreach ($ sort as $ k = >$ v) {unset ($ sort [$ k]); $ data = Combination ($ sort, $ num-1 ); foreach ($ data as $ row) {$ result [] = $ v. ','. $ row ;}} return $ result ;}$ starttime = explode ('', microtime (); $ arr = array,, 33); // This is a Combination of $ res = Combination ($ arr, 6 ); print_r ($ res); $ endtime = explode ('', microtime ()); $ thistime = $ endtime [0] + $ endtime [1]-($ starttime [0] + $ starttime [1]); $ thistime = round ($ thistime, 3 ); echo "time consumed on this webpage :". $ thistime. "Seconds ";
I tested a lot, this efficiency can also be 33 choose 5 more than 1 point to come out, but if you choose 6, there will be 500 error, I am IIS7.5 + PHP5.6 FAST-CGI mode! Why is the error 500? is the array too large? you need to call PHP. INI. Which parameter is
Reply to discussion (solution)
Enable the error display function of php, and you will see an error like Fatal error: Allowed memory size...
Insufficient memory!
The reason is that the memory allocated to php is not enough. ini_set ('memory _ limit', '500m') try again
I don't know what I understand, right?
Select M for N. if repeated values are allowed, it is better to call the value corresponding to the random number key name each time.
If repeated values are not allowed, use the shuffle () function to randomly arrange the values and then take the first M elements directly.