= 0; ) {...}"."/> = 0; ) {...}".">

Home >Backend Development >PHP Problem >what does miltiply mean in php

what does miltiply mean in php

藏色散人
藏色散人Original
2022-11-08 10:26:091695browse

If the word miltiply appears in a PHP library function, it usually means "multiplication"; if it is customized by a developer, it depends on the developer's intention and whether the wording is appropriate, such as custom The miltiply method is like "functionmul($a,$b){$lenA=strlen($a);$lenB=strlen($b);$result= '0';for($inxA=$lenA- 1;$ inxA>= 0; ) {...}".

what does miltiply mean in php

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What does miltiply mean in php?

If this word appears in a PHP library function, multiply usually represents "multiplication";

If it is customized, it depends on the author's intention and whether the wording is appropriate.

For example:

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= &#39;0&#39;;

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

        $re= &#39;&#39;;

        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= &#39;&#39;;

    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;

}

?>

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of what does miltiply mean in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn