PHP-覆盖一个输出,多个配置

PHP-覆盖一个输出,多个配置,php,if-statement,Php,If Statement,我有一个回声: echo 'Hello world'; 我可以在两个地方管理回声是否可见,我可以使用: global_option('show_echo'); 及 请告诉我如何从post\u选项覆盖global\u选项,例如: 在global_选项('show_echo')echo被设置为隐藏,在post_选项('show_echo')中可见然后输出回声 如何制作否则,如果优先于post\u选项,则意味着post\u选项可以覆盖global\u选项 建议我一个最简单的方法来实现这一点听起来您

我有一个回声:

echo 'Hello world';
我可以在两个地方管理回声是否可见,我可以使用:

global_option('show_echo');

请告诉我如何从
post\u选项
覆盖
global\u选项
,例如:

global_选项('show_echo')
echo被设置为隐藏,在
post_选项('show_echo')中可见然后输出回声

如何制作
否则,如果
优先于
post\u选项
,则意味着
post\u选项
可以覆盖
global\u选项


建议我一个最简单的方法来实现这一点

听起来您需要一个实现优先级顺序的函数:

function check_config( $key) {
    // Your question is unclear as to the exact logic necessary here
    $post = post_option( $key);
    if( isset( $post)) return $post;

    $global = global_option( $key);
    if( isset( $global)) return $global;

    return false;
}
那就用下面的话来称呼它:

if( check_config( 'show_echo')) {
}

您的代码目前是什么样子的?您在哪里遇到问题?多次重复相同的代码:
if(全局_选项('show_echo')和&post_选项('show_echo')){…}elseif(!全局_选项('show_echo')和&post_选项('show_echo')){..
如下所示
if( check_config( 'show_echo')) {
}