【问题标题】:How to echo an stdClass Object Array's array values如何回显 stdClass 对象数组的数组值
【发布时间】:2014-08-16 11:56:35
【问题描述】:

我在 STDClass 对象中有一个数组作为我的选择选项。我不明白如何回应它的价值观。

var $fields = array( array(
   'name'   => 'icon',
   'type'   => 'select',
   'items' => array(0 => 'news', 1 => 'technology', 2 => 'products'),
    ),  
);

然后在widget函数内:

function widget($args, $instance)
{
$inst = (object) wp_parse_args($instance, array(
        'icon'              => '',
        'title'             => '',
        'display_title'     => '',
        'content'           => '',
        'link_text'         => '',
    ));
}

在这个函数中 echo $inst->icon; 给了我钥匙。如何获得价值?

【问题讨论】:

  • wp_parse_args 是做什么的?
  • @BenRacicot 你的意思是$inst->icon 返回“图标”?
  • 我对 Wordpress 不熟悉,但你试过 'items' => array('news','technology','products')
  • @Adelphia 原来它应该在使用带有选择选项的数组时回显键。使用键作为标签。感谢您帮助指导我。

标签: php arrays wordpress


【解决方案1】:

您是否尝试过“旧”数组表示法而不是箭头?

echo $inst['icon'];

来源:这就是他们在本文档中打印值的方式:http://codex.wordpress.org/Function_Reference/wp_parse_args

【讨论】:

    猜你喜欢
    • 2012-05-28
    • 2014-10-30
    • 2013-01-13
    • 2021-02-07
    • 2018-02-10
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 2014-02-28
    相关资源
    最近更新 更多