函数名称中带有变量的匿名函数

时间:2019-12-30 07:21:32

标签: php wordpress

我正在尝试使用PHP函数做一些漂亮的事情。

我想调用一个函数,但是根据站点区域,我希望它调用其他函数。这是在WP主题激活中发生的,但是调用该函数的每个主题都有不同的独特功能。 las,我离题了:

$mb_theme_action_mbinout = function() {
    // this is code is for testing
    $mb_locations = array();
    for ($i = 1; $i <= 10; ++$i) {
        $mb_locations[] =   array(
                                'a' => 'Test item ' . $i,
                                'b' => 'loc0' . $i,
                                'c' => 'group1'
                            );
    }

    var_dump( $mb_locations );

};

$theme = function() {
    echo 'mb_theme_action_' . get_option('stylesheet'); // output: mb_theme_action_mbinout
};

$theme();

以上操作无效,但我也尝试过:

$theme = 'mb_theme_action_' . get_option('stylesheet');
$theme();

// also

$$theme();

我知道这不是常规的做法,但是想知道是否有一种可行的方法?它只会被调用一次。

0 个答案:

没有答案
相关问题