简体   繁体   中英

PHP question --> how do I retrieve the value of an object within an array?

Below is the structure of a multidomensional array. How can I get the value of "title" or any of the values within #object?

$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 )

The error that I get after implementing AJ's solution is:

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).

line 84 of node.tpl.php is what AJ suggested:

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

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

But it also looks like it might be accessible at:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM