PHP问题 - >如何检索数组中对象的值?

时间:2011-05-26 01:43:41

标签: php arrays multidimensional-array

下面是多维数组的结构。如何在#object中获取“title”或任何值的值?

$content (Array, 2 elements)
    links (Array, 5 elements)
    body (Array, 16 elements)
        #theme (String, 5 characters )
        #weight (Integer)
        #title (String, 4 characters )
        #access (Boolean)
        #label_display (String, 6 characters )
        #view_mode (String, 6 characters )
        #language (String, 2 characters ) 
        #field_name (String, 4 characters )
        #field_type (String, 17 characters )
        #field_translatable (String, 1 characters )
        #entity_type (String, 4 characters )
        #bundle (String, 7 characters )
        #object (Object) stdClass
            vid (String, 2 characters )
            uid (String, 1 characters )
            title (String, 55 characters ) **THIS IS THE VALUE THAT I NEED**
            log (String, 0 characters )
            status (String, 1 characters )

实施AJ解决方案后出现的错误是:

Notice: Undefined index: body in include() (line 84 of C:\wamp\www\sdnn_drupal\sites\all\themes\sdnn\node.tpl.php).
Notice: Trying to get property of non-object in include() (line 84 of C:\wamp\www\sdnn_drupal\sites\all\themes\sdnn\node.tpl.php).

node.tpl.php第84行是AJ建议的:

<?php echo $content['body']['#object']->title ?>

2 个答案:

答案 0 :(得分:4)

$title=$content['body']['#object']->title;

但它似乎也可以通过以下方式访问:

$title=$content['body']['#title'];

答案 1 :(得分:0)