函式名:bcpowmod()
適用版本:該函式在PHP 4 >= 4.0.4、PHP 5、PHP 7中可用。
用法:bcpowmod() 函式用於計算一個數字的給定次方然後取模。函式接受三個引數:底數(base),指數(exponent)和模數(modulus)。底數和指數可以是任意長度的十進位制數字符串,而模數必須是正整數。
語法:string bcpowmod ( string $base , string $exponent , string $modulus )
引數:
- base: 底數,可以是任意長度的十進位制數字符串。
- exponent: 指數,可以是任意長度的十進位制數字符串。
- modulus: 模數,必須是正整數。
返回值:計算結果作為一個字串返回。
示例:假設我們想要計算 (2的100次方) mod (11),我們可以使用 bcpowmod() 函式來實現。
$base = '2';
$exponent = '100';
$modulus = '11';
$result = bcpowmod($base, $exponent, $modulus);
echo $result; // 輸出 9
在這個示例中,我們使用 bcpowmod() 函式計算了 2的100次方並取模 11 的結果。最後的輸出是 9。