【问题标题】:PHP function MathPHP 函数数学
【发布时间】:2018-02-03 15:29:40
【问题描述】:

我必须创建一个 PHP 代码调用具有 2 个数字的函数并使用 echo 语句显示函数返回值。到目前为止,我只有贝娄。不知道我在哪里搞砸了或我需要添加什么。卡住了。

 <?php 

function myfunction( $argx = 5 , $arg4 = 4) {

return ($argx * $arg4);


}

echo ($argx * $arg4);

【问题讨论】:

  • 请完成任何随机的 PHP 教程,这里不是教 PHP 的地方。

标签: php function math echo


【解决方案1】:

你创建的函数现在可以用于例子

echo myfunction(7,8);

如果你只是这样做

echo myfunction();

一样
echo myfunction(5,4);

因为您已将这些值设为默认值。

读入 PHP 函数,例如 https://www.w3schools.com/php/php_functions.asp

【讨论】:

    【解决方案2】:

    这样试试:

    <?php
    //            +------------------ myfunction is the function name
    //            |       +---------- $argx is a parameter with the default value 5
    //            |       |        +- $arg4 is a parameter with the default value 4
    //            |       |        |
    function myfunction($argx=5, $arg4=4) {
        return ($argx * $arg4);
    }
    

    现在您可以使用echo myfunction(); 调用该函数

    echo myfunction();        // result is = 20  ! no parameters set = default (5 * 4)
    echo myfunction(10, 10);  // result is = 100 ! parameters 10 and 10 = (10 * 10)
    echo myfunction(10 * 10); // result is = 400 ! first parameter is 100, no seccond parameter set so default is 4 = (100 * 4)
    

    You can play with it here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多