在数组中使用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 ')'

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.

However you can user array_map to call same function on each element of an array :

http://us1.php.net/manual/fr/function.array-map.php

In your case,

'options'   => array_map('callback', $categories),

and your callback

function callback($category) {
    return __( $category->name , 'startbox' );
);