The M algorithm selected by PHPN cannot be printed out in a large array.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.