无法从数组中获取对象,不输出任何内容,数组print_r工作正常


cannot grab object from array, outputs nothing, array print_r works fine

我肯定少了一些愚蠢的东西,但我很累,无法理解到底是什么。

我有一个数组,打印得很好:

Array ( [0] => stdClass Object ( [comment_ID] => 20 [comment_post_ID] => 227 [comment_author] => admin [comment_author_email] => [comment_author_url] => [comment_author_IP] => ::1 [comment_date] => 2012-07-29 14:19:34 [comment_date_gmt] => 2012-07-29 14:19:34 [comment_content] => I'm attending this Event! [comment_karma] => 0 [comment_approved] => 1 [comment_agent] => [comment_type] => [comment_parent] => 0 [user_id] => 1 ) )

p.s.删除了一些隐私价值观。

现在我想获取comment_ID,但没有任何输出到浏览器。

php看起来像这样:

$current_user_comment = get_comments( array(
  'post_id' => $post->ID,
  'user_id' => get_current_user_id(),
  'number' => 1,
  'status' => 'approve',
  'type' => 'comment'
) );
print_r ( $current_user_comment );
echo $current_user_comment->comment_ID;

print_r的输出中可以看到,$current_user_comment是数组,而不是对象。并且所需对象位于该数组中的索引0处。

$current_user_comment[0]->commentID将起作用。