douyan4243 2014-01-20 10:44
浏览 27

在数组中使用foreach,数组本身位于数组中

am working on a wordpress admin panel using startbox admin panel, where I want to list all categories with slug and name inside an array but it seems impossible for me to make it work, here is my code

$args = array(
'type'                     => 'post',
'child_of'                 => 0,
'parent'                   => '',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'exclude'                  => '',
'include'                  => '',
'number'                   => '',
'taxonomy'                 => 'category',
'pad_counts'               => false 

);

$args = array(
   'orderby' => 'name',
   'order' => 'ASC'
);

$categories = get_categories($args);

// This much above code is given by wordpress to get all categories, mine starts below

class sb_slider_settings extends sb_settings {

function sb_slider_settings() {
    $this->slug = 'sb_slider_settings';
    $this->options = array(
        'on_off_news' => array(
                'type'      => 'select',
                'default'   => 'true',
                'label'     => __( 'Enable breaking news', 'startbox' ),
                'options'   => array(
                    'false' => __( 'No', 'startbox' ),
                    'true'  => __( 'Yes', 'startbox' ),
                )
            ),              
        'ticker_text' => array(
                'type'      => 'select',
                'default'   => 'true',
                'class'     => 'ticker_text',                   
                'label'     => __( 'Extract posts from', 'startbox' ),
                'options'   => array(
                         foreach($categories as $category) {
                             $category->slug => __( $category->name , 'startbox' ) ;
                         }
                )
            )

        );
        parent::__construct();
}
}

Error it shows,

Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')'

  • 写回答

2条回答 默认 最新

  • doumi1884 2014-01-20 10:46
    关注

    You can't execute code inside an array. An array is intended to have fixed values in it.

    http://es1.php.net/manual/en/language.types.array.php

    To do what you wanna do you must create a function and call that function inside your array.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀