Nic*_*oft 4 php arrays parsing php-parse-error
我有一个小问题.我目前在000webhost上有我的网站,并且以下行:
$price = explode(".",$item->sellingStatus->currentPrice)[0];
Run Code Online (Sandbox Code Playgroud)
导致以下错误:
解析错误:语法错误,第58行/home/a1257018/public_html/scripts/myfile.php中的意外'['
当它在localhost上没有引起这种情况时.代码应该工作... explode返回一个数组,[0]只需调用第一个项目.为什么这会引发错误?
jus*_*ing 10
此语法仅允许在PHP 5.4+中使用.您必须在旧版本中使用临时变量:
$tmp = explode('.', $item->sellingStatus->currentPrice);
$price = $tmp[0];
Run Code Online (Sandbox Code Playgroud)
已经讨论过SO.
| 归档时间: |
|
| 查看次数: |
1444 次 |
| 最近记录: |