PHP N选M算法 大数组打印不出来
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(1,2,3,4,5,6,7,8,9,1,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33);//这个是组合$res = Combination($arr,6);print_r($res);$endtime = explode(' ',microtime());$thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);$thistime = round($thistime,3);echo "本网页执行耗时:".$thistime." 秒";
我测试了好多,这个效率还可以33选5 1点多秒就出来了,但是选6的话,就出现500错误,我的是IIS7.5+PHP5.6 FAST-CGI模式!为啥会500错误,是不是数组太大,要调PHP.INI啊。哪个参数是
回复讨论(解决方案)
打开 php 的错误显示功能,你会看到 Fatal error: Allowed memory size of ...... 这样的错误
内存不够了!
考虑是给php分配的内存不够用,ini_set('memory_limit','500M')试下
不知道我理解的对不对
N选M,如果允许重复值,每次调用随机数键名对应的值就好
如果不允许重复值,使用shuffle()函数随机排列,然后直接取前M个元素

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...
