Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've something that You may like</p> <pre><code>function combination_number($k,$n){ $n = intval($n); $k = intval($k); if ($k &gt; $n){ return 0; } elseif ($n == $k) { return 1; } else { if ($k &gt;= $n - $k){ $l = $k+1; for ($i = $l+1 ; $i &lt;= $n ; $i++) $l *= $i; $m = 1; for ($i = 2 ; $i &lt;= $n-$k ; $i++) $m *= $i; } else { $l = ($n-$k) + 1; for ($i = $l+1 ; $i &lt;= $n ; $i++) $l *= $i; $m = 1; for ($i = 2 ; $i &lt;= $k ; $i++) $m *= $i; } } return $l/$m; } function array_combination($le, $set){ $lk = combination_number($le, count($set)); $ret = array_fill(0, $lk, array_fill(0, $le, '') ); $temp = array(); for ($i = 0 ; $i &lt; $le ; $i++) $temp[$i] = $i; $ret[0] = $temp; for ($i = 1 ; $i &lt; $lk ; $i++){ if ($temp[$le-1] != count($set)-1){ $temp[$le-1]++; } else { $od = -1; for ($j = $le-2 ; $j &gt;= 0 ; $j--) if ($temp[$j]+1 != $temp[$j+1]){ $od = $j; break; } if ($od == -1) break; $temp[$od]++; for ($j = $od+1 ; $j &lt; $le ; $j++) $temp[$j] = $temp[$od]+$j-$od; } $ret[$i] = $temp; } for ($i = 0 ; $i &lt; $lk ; $i++) for ($j = 0 ; $j &lt; $le ; $j++) $ret[$i][$j] = $set[$ret[$i][$j]]; return $ret; } </code></pre> <p>Here is how to use it:</p> <p>To get the number of combinations:</p> <pre><code>combination_number(3,10); // returns number of combinations of ten-elements set. </code></pre> <p>To get all possible combinations:</p> <pre><code>$mySet = array("A","B","C","D","E","F"); array_combination(3, $mySet); // returns all possible combinations of 3 elements of six-elements set. </code></pre> <p>Hope You make use of that.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload