[英]PHP question --> how do I retrieve the value of an object within an array?
下面是多維數組的結構。 如何獲取“title”的值或#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 )
我在實施 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 ?>
$title=$content['body']['#object']->title;
但它看起來也可以在以下位置訪問:
$title=$content['body']['#title'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.