dongyu1983 2016-04-18 15:12
浏览 17

函数中的数组 - 错误的值

I'm sending 3 arrays with all arguments equal to 1. So the output of 'd' should be 9 and 'n' also ought to be 9. Instead I get 39. Anyone knows why? This is function

<html>
<body>
<?php
function eq1($a,$b,$c)
{
 $d= $a[0]*$b[1]*$c[2]+$b[0]*$c[1]*$a[2]+$c[0]*$a[1]*$b[2];
 $n= $c[0]*$b[1]*$a[2]+$b[0]*$a[1]*$c[2]+$a[0]*$c[1]*$b[2];
echo $d;
echo $n;

}
?> 
</body>
</html> 

This is example of array definition $a= [1,1,1]; $b= [1,1,1]; $c= [1,1,1];

This is calling for fuction

//calculating for cramer method 
$dg=eq1($a,$b,$c);
  • 写回答

1条回答 默认 最新

  • dsolwotv00116 2016-04-18 15:28
    关注

    kubauser you've only echoed the '$d' and the '$n' variables, you want the function to return the value hence use the "return" keyword, otherwise it might return a random number or so...

    The syntax is as follows:

    <?php
        function func($a,$b)
        {
          $c = $a +$b;
          return $c;
        }
    
        echo func(3,5);
    <?
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考