Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-创建一个函数,返回n-1倍的零以及传递的参数_Php - Fatal编程技术网

PHP-创建一个函数,返回n-1倍的零以及传递的参数

PHP-创建一个函数,返回n-1倍的零以及传递的参数,php,Php,我试图创建一个包含两个参数的函数 一个可以是编号本身列表项 另一个可能是长度 然后像下面一样返回 myfunction(4, 2) // will be 40 myfunction(3, 1) // will be 3 myfunction(9, 4) // will be 9000 就你所描述的问题而言。我认为以下内容可能会对您有所帮助 echo myfunction(4, 2); function myfunction( $num, $length){ if( $num >

我试图创建一个包含两个参数的函数

一个可以是编号本身列表项 另一个可能是长度 然后像下面一样返回

myfunction(4, 2) // will be 40
myfunction(3, 1) // will be 3
myfunction(9, 4)  // will be 9000

就你所描述的问题而言。我认为以下内容可能会对您有所帮助

echo myfunction(4, 2);

function myfunction( $num, $length){
    if( $num > 0 ){
        while( $length > 1 ){
            $num .= 0;
            $length--;
        }
    } else { return null; }
    return $num;
}

你的逻辑是什么?参数与输出有什么关系?我假设3,1的结果应该是3?然后你基本上是在寻找第三个参数设置为“0”的str_pad…如果你认为特殊情况需要编写一个显式包装函数,那么就写一个吧…@misorude我已经编辑了描述。预期的reult是10,1还是100,1?@B001ᛦ 它应该是10,1=10,和100,1=100本身。在3的基础上,让我先试试这个