This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
我想写一个函数,它将一个字母数组作为参数,并选择一些字母.
假设您提供了8个字母的数组,并希望从中选择3个字母.然后你应该得到:
8! / ((8 - 3)! * 3!) = 56
Run Code Online (Sandbox Code Playgroud)
数组(或单词)返回,每个包含3个字母.
我有一个7个数字(1,2,3,4,5,6,7)的数组,我想要成对的5个数字,如(1,2,3,4,5),(1,2,3) ,4,6,),(1,2,3,4,7).(1,2,3,4,5)等于(4,5,3,1,2)
我想知道PHP或任何算法中是否有函数可以执行此操作?我不知道从哪里开始.你能帮助我吗 ?
我希望将7个给定数字(它们从一个数组中取出)的所有组合放入5个插槽中,无视顺序
我整天都在看PHP数组排列/组合问题..但仍然无法弄明白:/
如果我有一个像这样的数组:
20 //key being 0
20 //key being 1
22 //key being 2
24 //key being 3
Run Code Online (Sandbox Code Playgroud)
我需要组合如:
20, 20, 22 //keys being 0 1 2
20, 20, 24 //keys being 0 1 3
20, 22, 24 //keys being 0 2 3
20, 22, 24 //keys being 1 2 3
Run Code Online (Sandbox Code Playgroud)
我目前的代码给了我:
20, 22, 24
Run Code Online (Sandbox Code Playgroud)
因为它不想重复20 ...但这就是我需要的!
这是我的代码.它直接来自Php递归以获得字符串的所有可能性
function getCombinations($base,$n){
$baselen = count($base);
if($baselen == 0){
return;
}
if($n == 1){
$return = array();
foreach($base as $b){
$return[] = …Run Code Online (Sandbox Code Playgroud) combinations ×3
php ×3
algorithm ×2
arguments ×1
arrays ×1
operators ×1
permutation ×1
recursion ×1
symbols ×1