miltiply这个词如果出现在PHP库函数中,则通常代表“乘法”的意思;如果是开发者自定义的,要看这个开发者的意图和是否用词得当,例如自定义的miltiply方法如“functionmul($a,$b){$lenA=strlen($a);$lenB=strlen($b);$result= '0';for($inxA=$lenA- 1;$inxA>= 0; ) {...}”。

本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑。

miltiply在php中是什么意思?

如果这个词出现在PHP库函数中,multiply通常代表“乘法”;

如果是自定义的,要看作者的意图和是否用词得当。

比如:

PHP实现大数相加、大数相乘
最基本的模拟竖式的计算方法:

<?php

/* multiply

* a,b should be numeric

* @param $a string

* @param $b string

* @return string

*/

functionmul($a,$b)

{

    $lenA=strlen($a);

    $lenB=strlen($b);

    $result= '0';

    for($inxA=$lenA- 1;$inxA>= 0; --$inxA) {

        $re= '';

        for($i=$inxA+ 1;$i<$lenA; ++$i) {

            $re= "0" .$re;

        }

        $j= 0;

        for($inxB=$lenB- 1;$inxB>= 0; --$inxB) {

            $mul= (int)$a[$inxA] * (int)$b[$inxB] +$j;

            if($mul>= 10) {

                $j=floor($mul/ 10);

                $mul=$mul-$j* 10;

            } else {

                $j= 0;

            }

            $re= (string)$mul.$re;

        }

        if($j> 0)$re= (string)$j.$re;

        $result= add($result,$re);

    }

    return$result;

}

/**

* add

* a,b should be numeric

* @param $a string

* @param $b string

* @return string

*/

functionadd($a,$b)

{

    $lenA=strlen($a);

    $lenB=strlen($b);

    $j= 0;

    $re= '';

    for($inxA=$lenA- 1,$inxB=$lenB- 1; ($inxA>= 0 ||$inxB>= 0); --$inxA, --$inxB) {

        $itemA= ($inxA>= 0) ? (int)$a[$inxA] : 0;

        $itemB= ($inxB>= 0) ? (int)$b[$inxB] : 0;

        $sum=$itemA+$itemB+$j;

        if($sum> 9) {

            $j= 1;

            $sum=$sum- 10;

        } else {

            $j= 0;

        }

        $re= (string)$sum.$re;

    }

    if($j> 0)$re= (string)$j.$re;

    return$re;

}

?>


miltiply在php中是什么意思