简体   繁体   中英

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. 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.

As @mario said in the comments, you can only using array dereferencing in PHP 5.4+. Array dereferencing refers to accessing an array index directly from a function call, eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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