首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在stdClass对象类型的嵌套数组中显示数组值

如何在stdClass对象类型的嵌套数组中显示数组值
EN

Drupal用户
提问于 2018-12-12 09:40:41
回答 1查看 686关注 0票数 0

我很难弄清楚如何为特定字段呈现数组字段的值。到目前为止,我已经成功地查询了我的db并收集了节点值,并将其保存到我的购物车中。但是,我不知道如何将这些内容回显到一个表中,以便用户以最有效的方式查看仅与项目名称、数量和field_id相关的字段。

  1. 下面是将实体加载到数组中的代码:

if (isset($result)) { $scart_items_nids = array_keys($result);$scart_items = entity_load('node',$scart_items_nids);}

  1. 我运行以下输出来查看数组:

回声"";print_r($scart_items);回声" ";

  1. 这是我得到的输出:数组( => stdClass Object ( => 264 => 1 => Rxk => => 1 => 0 => 0 => 0 => => shopping_cart => und => 1544177045 => 1544177045 => 0 => 0 1544177045 1 Array )( Array (=>阵列( => 21 => => 21 )) =>阵列( =>阵列)( =>阵列( => 11 => => 11 )) =>阵列( =>数组( =>数组( =>示例游=> =>示例巡演))) =>阵列( =>数组( => Array ( => 1 => => 1))) => 0 => 1544177045 => => 1 => 0 =>管理员=> 8 => a:6:{s:16:"ckeditor_default";s:1:"t";s:20:"ckeditor_show_toggle";s:1:"t";s:14:"ckeditor_width";s:4:"100%";s:13:"ckeditor_lang";s:2:"en";s:18:"ckeditor_auto_lang";s:1:"t";s:7:"contact";i:0;) => stdClass对象( => 265 => 1 => Test => => 1 => 0 => 0 => 0 => 0 => shopping_cart => und => 1544177049 => 1544177049 => 0 1544177049 1 Array ( Array )=>阵列( => 12 => => 12 )) =>阵列( =>阵列)( =>阵列( => 11 => => 11 )) =>数组(=>阵列( =>阵列( =>示例游=> =>示例游))) =>阵列( =>数组( => Array ( => 1 => => 1))) => 0 => 1544177049 => => 1 => 0 =>管理员=> 8 => a:6:{s:16:"ckeditor_default";s:1:"t";s:20:"ckeditor_show_toggle";s:1:"t";s:14:"ckeditor_width";s:4:"100%";s:13:"ckeditor_lang";s:2:"en";s:18:"ckeditor_auto_lang";s:1:"t";s:7:"contact";i:0;} )
EN

回答 1

Drupal用户

发布于 2018-12-12 09:59:20

这里,$scart_items作为对象包含加载的节点。

代码语言:javascript
运行
复制
$item_details =array();
foreach($scart_items as $item){
  $temp = array();
  $temp['itemname'] = $scart_items->field_itemname['und'][0]['value'];
  $temp['feild_id'] = $scart_items->field_id['und'][0]['value'];
  $temp['quantity'] = $scart_items->field_quantity['und'][0]['value'];
  $item_details[] = $temp;
 }

$item_details返回所需的数组。

票数 0
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/273880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档