将两个不同函数的结果相乘

时间:2019-04-25 04:19:11

标签: php

我已将两个函数的结果放置在表的两个不同列中。在第三栏中,我想将两个结果相乘。乘法显示零。第一个结果是6,第二个结果是3-加法显示63(如字符串加法)。

<tr>
    <td>Economics</td><td><?php echo $e; ?></td><!--Economics marks-->
    <td><?php $gra = sg($e);  ?></td><!--Economics grade using function sg()-->
    <td><?php $grap = sgp($e); ?></td><!--Economics grade points using sgp() function.-->
    <td><?php echo $ec; ?></td><!--Economics credits-->
    <td><?php $ce = ce3($e); ?></td><!--Economics credits earned using function ce3()-->
    <td><?php echo $ce * $grap;  ?></td><!--multiplication of two function results - this should be 18 - 3 x 6 but shows 3.-->
</tr>

计算赚取积分的功能:-

function ce3($marks) {
    if ($marks == "A" || $marks == "CC") {
        $marks = "---";
        echo $marks;
    } else {
        $marks = 3;
        echo $marks;
    }
}

计算成绩的功能:-

function sgp ($marks) {

    if ($marks == "A" || $marks =="CC") {
        $marks = "---";
        echo $marks;
    } elseif ($marks < 40) {
        $marks = 0;
        echo $marks;
    } elseif ($marks >= 40 && $marks < 45) {
        $marks = 4;
        echo $marks;
    } elseif ($marks >= 45 && $marks < 50) {
        $marks = 5;
        echo $marks;
    } elseif ($marks >= 50 && $marks < 55) {
        $marks = 6;
        echo $marks;
    } elseif ($marks >= 55 && $marks < 60) {
        $marks = 7;
        echo $marks;
    } elseif ($marks >= 60 && $marks < 70) {
        $marks = 8;
        echo $marks;
    } elseif ($marks >= 70 && $marks < 80) {
        $marks = 9;
        echo $marks;
    } elseif ($marks >= 80) {
        $marks = 10;
        echo $marks;
    }
}

1 个答案:

答案 0 :(得分:1)

您在函数中缺少return语句...

function ce3($marks) {
    if ($marks == "A" || $marks == "CC") {
        $marks = "---";
        echo $marks;
    }
    else {$marks = 3;
        echo $marks;
    }
    return $marks;
}

您的sgp()功能也是如此。