0

我有以下(精简)代码:

$question = fetch_question($conn, $current_question);
var_dump($question);
echo $question["_id"];

fetch_question()使用$conn数据库连接来检索$current_question.

这给了我以下输出:

array(1) {
  [0]=>
  array(7) {
    ["_id"]=>
    string(1) "1"
    ["question"]=>
    string(10) "What's 2+2"
    ["answer1"]=>
    string(1) "1"
    ["answer2"]=>
    string(1) "2"
    ["answer3"]=>
    string(1) "3"
    ["answer4"]=>
    string(1) "4"
    ["is_right"]=>
    string(1) "4"
  }
}
<br />
<b>Notice</b>:  Undefined index: _id in <b>D:\Websites\htdocs\tests\general.php</b> on line <b>76</b><br />

现在我发现这很奇怪,_id定义很明确我不知道是什么让 PHP 表现得这样!

任何帮助,将不胜感激!

4

1 回答 1

1

只有在 StackOverflow 上看到这里的输出后,我才意识到我实际上需要$question[0]["_id"].

好吧,我们都知道这些小害虫的烦恼。

于 2012-04-12T19:47:44.123 回答