This function is only available in PHP 7.3.0 or later
Binomial coefficient - from Statists How To
Binomial coefficient - from Wikipedia
<?php
GMP gmp_binomial ( GMP|int|string $n, int $k )
where,
$n = The number of items
$k = The number of item to choose
?>
<?php
$dn01 = [ 'Thumb', 'Pointer', 'Middle', 'Ring', 'Pinky' ];
$n01 = count($dn01);
echo $n01 . ' finger names are:<br><br>';
for($x01 = 0; $x01 <= 4; $x01++)
{
if($x01 <= 2)
{
echo '(' . ($x01+1) . ') ' . $dn01[$x01] . ', ';
}
elseif($x01 == 3)
{
echo '(' . ($x01+1) . ') ' . $dn01[$x01] . ' and ';
}
else
{
echo '(' . ($x01+1) . ') ' . $dn01[$x01] . '.<br><br><br>';
}
}
echo 'How many subsets of 3 finger names
we can obtain from its 7 names?<br><br>';
echo 'Such an answer will be given by: ';
$ssa01 = gmp_binomial($n01, 3);
echo '<br><br>gmp_binomial( ' . $n01 . ', 3 ) = ' . $ssa01 .
' subsets.<br><br>The same thing as:<br><br>';
$ssb01 = gmp_div(gmp_fact($n01),
gmp_mul(gmp_fact(3),
gmp_fact(gmp_sub($n01, 3))));
echo 'gmp_div(gmp_fact(' . $n01 . '),
gmp_mul(gmp_fact(3),
gmp_fact(gmp_sub(' . $n01 . ' , 3)))) = ' .
$ssb01 . ' subsets.<br><br>
That is, a combination of 5 items 3
through 3 produces the following
subsets:<br><br>';
echo
'(01) Thumb, Pointer and Middley<br>
(02) Thumb, Pointer and Ring<br>
(03) Thumb, Pointer and Pinky<br>
(04) Thumb, Middley and Ring<br>
(05) Thumb, Middley and Pinky<br>
(06) Thumb, Ring and Pinky<br>
(07) Pointer, Middle and Ring<br>
(08) Pointer, Middle and Pinky<br>
(09) Pointer, Ring and Pinky<br>
(10) Middle, Ring and Pinky.';
?>