回撥函式,求積函式

weixin_34292287發表於2016-12-04
    <?php 

    // 回撥函式
    // 將sum 和 multiple 作為字串引數  傳遞給函式result
    // sum 和 multiple就是result的回撥函式


    // 求和函式
    function sum($a=10, $b=20){
        echo '現在是加法';
        return $a+$b;
    }


    // 求積函式
    function multiple($a=10, $b=20){
        echo '現在是乘法';
        return $a * $b;
    }

    function result($abc=1, $num2=2, $qqq='sum'){
        return $qqq($abc, $num2);
        // return sum($num1, $num2);
    }

    echo result(4,5);
    echo '<br>';
    echo result(4,5,'multiple');


 ?>

相關文章