PHP gmp_root() 函数

PHP gmp_root() 函数

PHP 语言开发了一个名为 gmp_root() 的函数,它可以返回给定参数或数字的 N 次方根的整数值。

语法

这个语法展示了 GMP 函数来获取基础参数的根值。

<?php
gmp_root(base_value,n_value);
?>

参数

  • 该函数接受两个变量: $base值和$n值。这两个变量对gmp_root()函数及其操作都是必要的。
  • 在PHP 5.6及之后的版本中,参数是一个GMP对象。我们也可以将数字字符串作为GMP参数传递。字符串值将数据转换为数字值。
    • $base_value :它是GMP数,其整数部分作为n次方的根被返回。
    • $n_value :它是数的第n个正根。它是一个整数值。

返回值

该函数将$num的第N个根的整数值作为正的GMP数返回。

示例

示例1: 给定示例展示了给定输入值的”最后一次根值的整数部分”。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_root() Function </h4>
<p>The function shows the integer value of the "n-th" root of a GMP parameter or number.
 </p>
<?php
value1 = gmp_root("5", "2");value2 = gmp_root("15", "9");
value3 = gmp_root("52", "1");value4 = gmp_root("124", "3");
echo "The Integer part of the N'th root value: " .value1;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value2;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value3;
echo "<br/>";
echo " The Integer part of the N'th root value:  " .value4;
?>
</body>
</html>

输出:

输出图像显示给定数据的根值的整数部分。

PHP gmp_root() 函数

示例2: 给出的示例展示了给定输入值的“最后根值的整数部分”。在这里,我们可以使用负基值,但它在第n个值上不起作用。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_root() Function </h4>
<?php
value1 = gmp_root("-14", "1");value2 = gmp_root("-15", "9");
value3 = gmp_root("14", "-1");
echo "The Integer part of the N'th root value: " .value1;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value2;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value3;
?>
</body>
</html>

输出:

输出图像显示给定数据的根值的整数部分。

PHP gmp_root() 函数

示例3: 给定示例展示了给定变量值的“最后一个根值的整数部分”。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_root() Function </h4>
<?php
var_val1  = "2";var_val2 = "5";
var_val3 = "15";var_val4 = "60";
var_val5 = "48";value1 = gmp_root(var_val4,var_val1);
value2 = gmp_root(var_val3, var_val2);value3 = gmp_root(var_val4,var_val2);
echo "The Integer part of the N'th root value: " .value1;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value2;
echo "<br/>";
echo " The Integer part of the N'th root value: " .$value3;
?>
</body>
</html>

输出:

输出图像显示给定数据的根值的整数部分。

PHP gmp_root() 函数

示例4: 给定示例展示了给定GMP参数的最后一个根值的”整数部分”。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_root() Function </h4>
<?php
var_val1  = "5";var_val2 = "2";
var_val3 = gmp_neg("-15");var_val4 = gmp_com("-60");
var_val5 = gmp_init("1111");value1 = gmp_root(var_val4,var_val1);
value2 = gmp_root(var_val3, var_val2);value3 = gmp_root(var_val5,var_val1);
value4 = gmp_root(var_val5, var_val2);
echo "The Integer part of the N'th root value: " .value1;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value2;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value3;
echo "<br/>";
echo " The Integer part of the N'th root value: " .$value4;
?>
</body>
</html>

输出:

输出图像显示给定数据的根值的整数部分。

PHP gmp_root() 函数

示例5: 给定的示例显示了给定二进制值的“最后一个根的整数部分”。

<!DOCTYPE html>
<html>
<body>
<h4> PHP gmp_root() Function </h4>
<?php
var_val1  = "5";var_val2 = "2";
var_val3 = gmp_init("11111",2);var_val4 = gmp_init("111",2);
var_val5 = gmp_init("1111",2);value1 = gmp_root(var_val4,var_val1);
value2 = gmp_root(var_val3, var_val2);value3 = gmp_root(var_val5,var_val1);
value4 = gmp_root(var_val5, var_val2);
echo "The Integer part of the N'th root value: " .value1;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value2;
echo "<br/>";
echo " The Integer part of the N'th root value: " .value3;
echo "<br/>";
echo " The Integer part of the N'th root value: " .$value4;
?>
</body>
</html>

输出:

输出图像显示了给定数据的根值的整数部分。

PHP gmp_root() 函数

结论

gmp_root()函数移除了php语言中的冗长代码部分,为开发者提供了简便的操作。它返回整数数据和给定参数的第n个值的一部分。

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程