functions - Condition OR for current user ID

I'm tryng without success to create a custom backend based on user ID, if user id is different the 1 or different t

I'm tryng without success to create a custom backend based on user ID, if user id is different the 1 or different then 2 show custom backend.

This is my code but it doesn't work, any help would be very appreciate it.

if ($current_user_id != 1 || $current_user_id != 2){ show custom backend

Thank you

I'm tryng without success to create a custom backend based on user ID, if user id is different the 1 or different then 2 show custom backend.

This is my code but it doesn't work, any help would be very appreciate it.

if ($current_user_id != 1 || $current_user_id != 2){ show custom backend

Thank you

Share Improve this question edited Jun 2, 2020 at 15:42 shanebp 5,0856 gold badges27 silver badges40 bronze badges asked Jun 2, 2020 at 15:38 user1818326user1818326 133 bronze badges 1
  • 3 if you're trying to show the custom backend if the user is not 1/2 then that logic will not work unless the user ID is both 1 and 2 at the same time, which is not possible. The logic you've written is not the logic you wanted. If the user is 2 then it resolves to true because the user is not 1. If the user is 1 then it resolves to 2 because the user is not 2. Remember, the computer takes things literally, and will do exactly what it says, not what it meant. – Tom J Nowell Commented Jun 2, 2020 at 16:07
Add a comment  | 

2 Answers 2

Reset to default 2

You do not want an OR, you want an AND.

Follow it through and substitute the values. If we are user 1, then it's true because we are not user 2, and true OR false resolves to true. Only one of them needs to be true for an OR to be true. If we are user 2, then it's true because we are not user 1, and false OR true also resolves to true.

Remember, a or b is true if A, B, or both are true. I know what you meant, but the computer does not, and you have to be extremely exact.

When you say I do not want A or B, what you really meant was I do not want A and I do not want B.

so replace this:

if user is not 1 or user is not 2

with:

if user is not 1 and user is not 2

Or better yet:

if user is not in this array [ 1, 2]

Use: get_current_user_id()

$current_user_id = get_current_user_id();
if ($current_user_id != 1 && $current_user_id != 2){ 
    //show custom backend
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742379812a4432902.html

相关推荐

  • functions - Condition OR for current user ID

    I'm tryng without success to create a custom backend based on user ID, if user id is different the 1 or different t

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信