简体   繁体   English

PHP解析错误:语法错误,意外的'['

[英]PHP Parse error: syntax error, unexpected '['

I started receiving a strange PHP error, the script was working fine on the server, but when I set up locally I get a PHP parse error but everything is looking good. 我开始收到一个奇怪的PHP错误,该脚本在服务器上运行良好,但是当我在本地设置时,我得到了一个PHP解析错误,但一切看起来都很好。 The error is on this line: 错误在此行上:

$MaxBet = array_values($maxbet)[$Cnt];

From this snippet 从这个片段

$Cnt = 0;
foreach ($pcent as $val) {
    $MaxBet = array_values($maxbet)[$Cnt];
    $Payout = array_values($payout)[$Cnt];
    echo "<a href='#' id={$Cnt}>Less than {$val} Max bet:{$MaxBet} Payout:x{$Payout}</a><br>";
    $Cnt++;
}

Both web server and local setup using nginx and php5-fpm. 使用nginx和php5-fpm的Web服务器和本地设置。

As @mario said in the comments, you can only using array dereferencing in PHP 5.4+. 正如@mario在评论中所说,您只能在PHP 5.4+中使用数组解引用。 Array dereferencing refers to accessing an array index directly from a function call, eg: 数组解引用是指直接从函数调用中访问数组索引,例如:

$MaxBet = array_values($maxbet)[$Cnt];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM