dslijian2015 2013-02-12 14:53
浏览 18

使用PHP以可编程方式打印所有数组结果?

I want to print all results of the taxonomy_vocabulary_11 array (this is a Drupal 7 site). If I use <?php print render($content['taxonomy_vocabulary_11'][0]['#title']); ?> I get only one result.

I´ve usuccessfully tried

<?php foreach ($content->taxonomy_vocabulary_11 as $key => $value): $terms = $value['#title']; ?>
<?php print $terms; ?>
<?php endforeach?>

I get this error: Notice: Trying to get property of non-object

Now, this is the output I get using devel module (dpm($node);)

(object) array(
  'vid' => '5178',
  'uid' => '1',
  'title' => 'PROYECTO',
  'log' => '',
  'status' => '1',
  'comment' => '2',
  'promote' => '0',
  'sticky' => '0',
  'nid' => '155',
  'type' => 'jornadas',
  'language' => 'und',
  'created' => '1095048000',
  'changed' => '1360589684',
  'tnid' => '0',
  'translate' => '0',
  'revision_timestamp' => '1360589684',
  'revision_uid' => '1',
  'taxonomy_vocabulary_4' => array(),
  'taxonomy_vocabulary_6' => array(
    'und' => array(
      array(
        'tid' => '33',
        'taxonomy_term' => (object) array(
            'tid' => '33',
            'vid' => '6',
            'name' => 'Jornadas Gratuitas',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_6',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_7' => array(
    'und' => array(
      array(
        'tid' => '40',
        'taxonomy_term' => (object) array(
            'tid' => '40',
            'vid' => '7',
            'name' => 'Para PH',
            'description' => '',
            'format' => NULL,
            'weight' => '-10',
            'vocabulary_machine_name' => 'vocabulary_7',
          ),
      ),
    ),
  ),
  'taxonomy_vocabulary_11' => array(
    'und' => array(
      array(
        'tid' => '262',
        'taxonomy_term' => (object) array(
            'tid' => '262',
            'vid' => '11',
            'name' => 'colegios',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
      array(
        'tid' => '543',
        'taxonomy_term' => (object) array(
            'tid' => '543',
            'vid' => '11',
            'name' => 'derecho',
            'description' => '',
            'format' => NULL,
            'weight' => '0',
            'vocabulary_machine_name' => 'vocabulary_11',
          ),
      ),
    ),
  ),
  'body' => array(
    'und' => array(
      array(
        'value' => "

I´ve also tried <?php print render($content['taxonomy_vocabulary_11']); ?> to treat the taxonomy as any other field, but it won´t print anything.

Note: If I go and do print $content['taxonomy_vocabulary_11']; it just print the word array.

What´s wrong in my approach?

  • 写回答

2条回答 默认 最新

  • dou44481 2013-02-12 15:05
    关注

    Try:

    foreach ($content['taxonomy_vocabulary_11'] as $tv11) {
        print render($tv11['#title']);
    }
    

    I dont use drupal but this should work if i understood how the $content['taxonomy_vocabulary_11'] array is structured.

    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?