Parse error: syntax error, unexpected '*' [duplicate]

若如初见. 提交于 2019-12-25 19:06:44

问题


My code:

<?php

    function ci($principle, $rate, $time) {

        $ci = ($principle * (( (1 + $rate / 100) ** $time) - 1));
        echo $ci;

    }

?>
<?php
    echo ci(10,10,10);
?>

And when I am running it, it gives the following error

Parse error: syntax error, unexpected '*' in D:\Xampp\htdocs\php\functions.php on line 4

Please tell me what's the error in line 4 ($ci = ($principle * (((1+$rate/100)**$time)-1));) ?


回答1:


Your syntax as it is, is correct. The problem is your PHP version. The ** operator was introduced in PHP 5.6 and you probably have something below.

So either update your PHP or use pow().




回答2:


OP had an extra * over

(1 + $rate / 100) ** $time)

which results into PHP syntax error Unexpected * within PHP verison < 5.6.0 and works fine for the higher versions

function ci($principle, $rate, $time) {
    $ci = ($principle * (((1 + $rate / 100) * $time) - 1));
                                         //^^ removed extra *
    echo $ci;
}

ci(10, 10, 10);

Demo



来源:https://stackoverflow.com/questions/32905365/parse-error-syntax-error-unexpected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!