函数内部传递的PHP参数不起作用


php parameters passed inside function is not working

在php/wordpress我做了一个函数。我想在函数中传递一些参数,这样它就会根据这些参数显示结果。现在我的函数代码是这样的

$user_id = get_current_user_id();
function check_user_access($role, $action = NULL ) {
    if( $role == 'subscriber') {
        if( $action = 'check_customer' ) {
            $check_customer = $wpdb->get_var("SELECT COUNT(id) FROM `table1` WHERE `user_id` = $user_id");
            return $check_customer;
        }
        if( $action = 'check_users' ) {
            $check_users = $wpdb->get_var("SELECT COUNT(id) FROM `table2` WHERE `user_id` = $user_id");
            return $check_users;
        }
    }
}

现在我像这样使用这个函数

$role = 'subscriber';
$check_customers = check_user_access($role, $action = 'check_users' );
if( $check_users <=1 ) {
    //do something;
}
if( $check_users > 1 ) {
    //do something other;
}

但它显示了$action = 'check_customer'的结果。表示它在第一个块条件下工作。有人能告诉我怎么解决这个问题吗?我做错了什么吗?

修改

 if( $action = 'check_customer' ) {}

if( $action == 'check_customer' ) {}

=表示赋值运算符

==表示比较运算符

from here