解析错误:mysqli_fetch_array()中的语法错误

时间:2015-01-02 19:42:28

标签: php

解析错误:语法错误,意外' [',期待','或';'在第8行的/home/u844411171/public_html/index.php

我遇到mysqli_fetch_array()的问题。我使用mysqli_fetch_array():

if (isset($_SESSION["user_id"])) {
$query = "SELECT typ FROM `uzivatel` WHERE id = " . $_SESSION["user_id"];
$uzivatel = $mysqli->query($query);
$prava = mysqli_fetch_array($uzivatel)[0];
}

$celkemClenu = "SELECT count(`id`) FROM 
        `uzivatel`" or die("Error in the consult.." . mysqli_error($mysqli));
$result = $mysqli->query($celkemClenu);
echo "<p>Celkem členů: " . mysqli_fetch_array($result)[0];

Plz,哪里有问题?

1 个答案:

答案 0 :(得分:3)

您的PHP是older than 5.4,这是添加函数返回的直接数组解除引用的时候:

echo foo()[0]; // ok in 5.4, syntax error in older versions

解决方法,使用临时变量来存储数组:

$temp = foo();
echo $temp[0];