PHP - 解析错误:语法错误,意外的 '[' - 关联数组

3
我写了一段完美运行的代码,但后来重新安装了操作系统,现在我尝试运行它时不断出现错误。我使用的是IIS 8.0、WebMatrix和PHP 5.3。
以下是有问题的代码片段:
<?php 
     if (!$me->get_details()['quote']) : //<--error is here
?>
     <p class="quote">Write some motivational quote.</p>
<?php
     else :
?>
     <p class="quote"><?= $me->get_details()['quote']?></p>
<?php endif; ?>

函数 get_details() 返回一个关联数组,其中包含来自数据库的数据。

这里可能会出现什么问题?


检查您的PHP版本并在手册中查看数组解引用。 - PeeHaa
1个回答

2

您无法在PHP 5.3中以这种方式取消引用。

您需要执行以下操作:

$result = $me->get_details();

if (!$result['quote']) : 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接