PHP中的括号和数组
在本地主机上运行此操作,一切正常。现在,当在web服务器上运行它时,我得到了关于第一行中[]的解析错误。这不是在PHP中声明数组的合法方法吗PHP中的括号和数组,php,arrays,web,Php,Arrays,Web,在本地主机上运行此操作,一切正常。现在,当在web服务器上运行它时,我得到了关于第一行中[]的解析错误。这不是在PHP中声明数组的合法方法吗 function render($template, $values = []) { // if template exists, render it if (file_exists("../templates/$template")) { // extract variables into local scope
function render($template, $values = [])
{
// if template exists, render it
if (file_exists("../templates/$template"))
{
// extract variables into local scope
extract($values);
// render template
require("../templates/$template");
}
括号语法可以从PHP5.4开始使用。尝试使用
array()
而不是中的[]
,现在可以使用[]
定义数组。关于语法的其他一切都是一样的
$var = array('key' => 'val');
PHP5.4及更高版本
$var = ['key' => 'var'];
取决于php版本(php 5.4+用于[]
)。