将数组传递给函数

用户名

我在sample.php中有以下PHP代码:

<html>
    <head>
       <title>
           PHP Test
       </title>
       <?php
          include "sample1.php";
       ?>
    </head>
    <body>
        <?php     
            echo "<br> ";       
            echo arrayAdder([1,2,3,4]);
            echo "<br> ";
        ?>      
    </body>
</html>

这是我的函数位于sample1.php中

function arrayAdder($array){
    $total = count($array);
    return $total;
}

我试图在浏览器中运行sample.php,但发生错误:

Parse error: syntax error, unexpected '[', expecting ')' in C:\xampp\htdocs\sample.php on line 13

我的代码有什么问题?

ug田玻色

array shorthand syntax被支持PHP >= 5.4新功能)。您的版本可能不支持该语法。检查版本。现在尝试一下-

    <?php     
        echo "<br> ";       
        echo arrayAdder(array(1,2,3,4));
        echo "<br> ";
    ?>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章